function MenuDevelGenerate::validateDrushParams

Same name in other branches
  1. 8.x-1.x devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MenuDevelGenerate::validateDrushParams()
  2. 4.x devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MenuDevelGenerate::validateDrushParams()

Overrides DevelGenerateBaseInterface::validateDrushParams

File

devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php, line 188

Class

MenuDevelGenerate
Provides a MenuDevelGenerate plugin.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

public function validateDrushParams(array $args, array $options = []) : array {
    $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 ?: 3;
    $values['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;
}