protected function MenuDevelGenerate::generateMenus in Devel 8
Same name and namespace in other branches
- 8.3 devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MenuDevelGenerate::generateMenus()
- 8.2 devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MenuDevelGenerate::generateMenus()
- 4.x devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MenuDevelGenerate::generateMenus()
Generates new menus.
Parameters
int $num_menus: Number of menus to create.
int $title_length: (optional) Maximum length per menu name.
Return value
array Array containing the generated vocabularies id.
1 call to MenuDevelGenerate::generateMenus()
- MenuDevelGenerate::generateElements in devel_generate/
src/ Plugin/ DevelGenerate/ MenuDevelGenerate.php - Business logic relating with each DevelGenerate plugin
File
- devel_generate/
src/ Plugin/ DevelGenerate/ MenuDevelGenerate.php, line 300
Class
- MenuDevelGenerate
- Provides a MenuDevelGenerate plugin.
Namespace
Drupal\devel_generate\Plugin\DevelGenerateCode
protected function generateMenus($num_menus, $title_length = 12) {
$menus = array();
for ($i = 1; $i <= $num_menus; $i++) {
$name = $this
->getRandom()
->word(mt_rand(2, max(2, $title_length)));
$menu = $this->menuStorage
->create(array(
'label' => $name,
'id' => 'devel-' . Unicode::strtolower($name),
'description' => $this
->t('Description of @name', array(
'@name' => $name,
)),
));
$menu
->save();
$menus[$menu
->id()] = $menu
->label();
}
return $menus;
}