You are here

public function ConfigurationForm::buildForm in Menu Entity Index 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/ConfigurationForm.php, line 50

Class

ConfigurationForm
Provides a configuration form for administrative settings.

Namespace

Drupal\menu_entity_index\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this->tracker
    ->getConfiguration();
  $form['all_menus'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Track all menus'),
    '#default_value' => $config
      ->get('all_menus'),
  ];
  $form['menus'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Tracked menus'),
    '#description' => $this
      ->t('Select menus that should be included in menu entity index.'),
    '#options' => $this->tracker
      ->getAvailableMenus(),
    '#default_value' => $config
      ->get('menus'),
    '#states' => [
      'invisible' => [
        ':input[name="all_menus"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['entity_types'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Tracked entity types'),
    '#description' => $this
      ->t('Select entity types that should be included in menu entity index.'),
    '#options' => $this->tracker
      ->getAvailableEntityTypes(),
    '#default_value' => $config
      ->get('entity_types'),
  ];
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save configuration'),
    '#button_type' => 'primary',
  ];
  $form['actions']['rebuild'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Rebuild index'),
    '#button_type' => 'secondary',
    '#submit' => [
      [
        get_class($this),
        'rebuildIndex',
      ],
    ],
  ];
  $form['#theme'] = 'system_config_form';
  return $form;
}