function MenuDevelGenerate::generateElements
Same name in other branches
- 4.x devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MenuDevelGenerate::generateElements()
- 5.x devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MenuDevelGenerate::generateElements()
Overrides DevelGenerateBase::generateElements
File
-
devel_generate/
src/ Plugin/ DevelGenerate/ MenuDevelGenerate.php, line 190
Class
- MenuDevelGenerate
- Provides a MenuDevelGenerate plugin.
Namespace
Drupal\devel_generate\Plugin\DevelGenerateCode
public function generateElements(array $values) {
// If the create new menus checkbox is off, set the number of new menus to 0.
if (!isset($values['existing_menus']['__new-menu__']) || !$values['existing_menus']['__new-menu__']) {
$values['num_menus'] = 0;
}
else {
// Unset the aux menu to avoid attach menu new items.
unset($values['existing_menus']['__new-menu__']);
}
// Delete custom menus.
if ($values['kill']) {
$this->deleteMenus();
$this->setMessage($this->t('Deleted existing menus and links.'));
}
// Generate new menus.
$new_menus = $this->generateMenus($values['num_menus'], $values['title_length']);
if (!empty($new_menus)) {
$this->setMessage($this->t('Created the following new menus: @menus', array(
'@menus' => implode(', ', $new_menus),
)));
}
// Generate new menu links.
$menus = $new_menus;
if (isset($values['existing_menus'])) {
$menus = $menus + $values['existing_menus'];
}
$new_links = $this->generateLinks($values['num_links'], $menus, $values['title_length'], $values['link_types'], $values['max_depth'], $values['max_width']);
$this->setMessage($this->t('Created @count new menu links.', array(
'@count' => count($new_links),
)));
}