You are here

public function MenuDevelGenerate::settingsForm in Devel 8.3

Same name and namespace in other branches
  1. 8 devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MenuDevelGenerate::settingsForm()
  2. 8.2 devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MenuDevelGenerate::settingsForm()
  3. 4.x devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MenuDevelGenerate::settingsForm()

Returns the form for the plugin.

Return value

array The array of default setting values, keyed by setting names.

Overrides DevelGenerateBase::settingsForm

File

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

Class

MenuDevelGenerate
Provides a MenuDevelGenerate plugin.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $menu_enabled = $this->moduleHandler
    ->moduleExists('menu_ui');
  if ($menu_enabled) {
    $menus = [
      '__new-menu__' => $this
        ->t('Create new menu(s)'),
    ] + menu_ui_get_menus();
  }
  else {
    $menus = menu_list_system_menus();
  }
  $form['existing_menus'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Generate links for these menus'),
    '#options' => $menus,
    '#default_value' => [
      '__new-menu__',
    ],
    '#required' => TRUE,
  ];
  if ($menu_enabled) {
    $form['num_menus'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Number of new menus to create'),
      '#default_value' => $this
        ->getSetting('num_menus'),
      '#min' => 0,
      '#states' => [
        'visible' => [
          ':input[name="existing_menus[__new-menu__]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ];
  }
  $form['num_links'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Number of links to generate'),
    '#default_value' => $this
      ->getSetting('num_links'),
    '#required' => TRUE,
    '#min' => 0,
  ];
  $form['title_length'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Maximum length for menu titles and menu links'),
    '#description' => $this
      ->t('Text will be generated at random lengths up to this value. Enter a number between 2 and 128.'),
    '#default_value' => $this
      ->getSetting('title_length'),
    '#required' => TRUE,
    '#min' => 2,
    '#max' => 128,
  ];
  $form['link_types'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Types of links to generate'),
    '#options' => [
      'node' => $this
        ->t('Nodes'),
      'front' => $this
        ->t('Front page'),
      'external' => $this
        ->t('External'),
    ],
    '#default_value' => [
      'node',
      'front',
      'external',
    ],
    '#required' => TRUE,
  ];
  $form['max_depth'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Maximum link depth'),
    '#options' => range(0, $this->menuLinkTree
      ->maxDepth()),
    '#default_value' => floor($this->menuLinkTree
      ->maxDepth() / 2),
    '#required' => TRUE,
  ];
  unset($form['max_depth']['#options'][0]);
  $form['max_width'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Maximum menu width'),
    '#default_value' => $this
      ->getSetting('max_width'),
    '#description' => $this
      ->t("Limit the width of the generated menu's first level of links to a certain number of items."),
    '#required' => TRUE,
    '#min' => 0,
  ];
  $form['kill'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Delete existing custom generated menus and menu links before generating new ones.'),
    '#default_value' => $this
      ->getSetting('kill'),
  ];
  return $form;
}