function MenuDevelGenerate::validateDrushParams

Same name in other branches
  1. 4.x devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MenuDevelGenerate::validateDrushParams()
  2. 5.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 224

Class

MenuDevelGenerate
Provides a MenuDevelGenerate plugin.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

public function validateDrushParams($args, $options = []) {
    $link_types = array(
        'node',
        'front',
        'external',
    );
    $values = array(
        'num_menus' => array_shift($args),
        'num_links' => array_shift($args),
        'kill' => $this->isDrush8() ? drush_get_option('kill') : $options['kill'],
        'pipe' => $this->isDrush8() ? drush_get_option('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;
}