public function MenuDevelGenerate::validateDrushParams in Devel 4.x
Same name and namespace in other branches
- 8.3 devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MenuDevelGenerate::validateDrushParams()
- 8 devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MenuDevelGenerate::validateDrushParams()
- 8.2 devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MenuDevelGenerate::validateDrushParams()
Responsible for validating Drush params.
Parameters
array $args: The command arguments.
array $options: The commend options.
Return value
array An array of values ready to be used for generateElements().
Overrides DevelGenerateBaseInterface::validateDrushParams
File
- devel_generate/
src/ Plugin/ DevelGenerate/ MenuDevelGenerate.php, line 234
Class
- MenuDevelGenerate
- Provides a MenuDevelGenerate plugin.
Namespace
Drupal\devel_generate\Plugin\DevelGenerateCode
public function validateDrushParams(array $args, array $options = []) {
$link_types = [
'node',
'front',
'external',
];
$values = [
'num_menus' => array_shift($args),
'num_links' => array_shift($args),
'kill' => $options['kill'],
'pipe' => $options['pipe'],
'link_types' => array_combine($link_types, $link_types),
];
$max_depth = array_shift($args);
$max_width = array_shift($args);
$values['max_depth'] = $max_depth ? $max_depth : 3;
$values['max_width'] = $max_width ? $max_width : 8;
$values['title_length'] = $this
->getSetting('title_length');
$values['existing_menus']['__new-menu__'] = TRUE;
if ($this
->isNumber($values['num_menus']) == FALSE) {
throw new \Exception(dt('Invalid number of menus'));
}
if ($this
->isNumber($values['num_links']) == FALSE) {
throw new \Exception(dt('Invalid number of links'));
}
if ($this
->isNumber($values['max_depth']) == FALSE || $values['max_depth'] > 9 || $values['max_depth'] < 1) {
throw new \Exception(dt('Invalid maximum link depth. Use a value between 1 and 9'));
}
if ($this
->isNumber($values['max_width']) == FALSE || $values['max_width'] < 1) {
throw new \Exception(dt('Invalid maximum menu width. Use a positive numeric value.'));
}
return $values;
}