You are here

public function MenuDevelGenerate::settingsForm in Devel 8

Same name and namespace in other branches
  1. 8.3 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 107

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 = array(
      '__new-menu__' => $this
        ->t('Create new menu(s)'),
    ) + menu_ui_get_menus();
  }
  else {
    $menus = menu_list_system_menus();
  }
  $form['existing_menus'] = array(
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Generate links for these menus'),
    '#options' => $menus,
    '#default_value' => array(
      '__new-menu__',
    ),
    '#required' => TRUE,
  );
  if ($menu_enabled) {
    $form['num_menus'] = array(
      '#type' => 'number',
      '#title' => $this
        ->t('Number of new menus to create'),
      '#default_value' => $this
        ->getSetting('num_menus'),
      '#min' => 0,
      '#states' => array(
        'visible' => array(
          ':input[name="existing_menus[__new-menu__]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
  }
  $form['num_links'] = array(
    '#type' => 'number',
    '#title' => $this
      ->t('Number of links to generate'),
    '#default_value' => $this
      ->getSetting('num_links'),
    '#required' => TRUE,
    '#min' => 0,
  );
  $form['title_length'] = array(
    '#type' => 'number',
    '#title' => $this
      ->t('Maximum number of characters in menu and menu link names'),
    '#description' => $this
      ->t('The minimum length is 2.'),
    '#default_value' => $this
      ->getSetting('title_length'),
    '#required' => TRUE,
    '#min' => 2,
    '#max' => 128,
  );
  $form['link_types'] = array(
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Types of links to generate'),
    '#options' => array(
      'node' => $this
        ->t('Nodes'),
      'front' => $this
        ->t('Front page'),
      'external' => $this
        ->t('External'),
    ),
    '#default_value' => array(
      'node',
      'front',
      'external',
    ),
    '#required' => TRUE,
  );
  $form['max_depth'] = array(
    '#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'] = array(
    '#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'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Delete existing custom generated menus and menu links before generating new ones.'),
    '#default_value' => $this
      ->getSetting('kill'),
  );
  return $form;
}