You are here

public function MegaMenuAdd::form in The Better Mega Menu 2.x

Same name and namespace in other branches
  1. 8 src/Form/MegaMenuAdd.php \Drupal\tb_megamenu\Form\MegaMenuAdd::form()

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Form/MegaMenuAdd.php, line 58

Class

MegaMenuAdd
Form handler for adding MegaMenuConfig entities.

Namespace

Drupal\tb_megamenu\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $menus = menu_ui_get_menus();
  $info = $this->themeHandler
    ->listInfo();
  $themes = [];
  foreach ($info as $name => $theme) {
    if (!isset($theme->info['hidden'])) {
      $themes[$name] = $theme->info['name'];
    }
  }
  $default = $this->config
    ->get('system.theme')
    ->get('default');
  $form['menu'] = [
    '#type' => 'select',
    '#options' => $menus,
    '#title' => $this
      ->t('Menu'),
    '#maxlength' => 255,
    '#default_value' => NULL,
    '#description' => $this
      ->t("Drupal Menu to use for the Mega Menu."),
    '#required' => TRUE,
  ];
  $form['theme'] = [
    '#type' => 'select',
    '#options' => $themes,
    '#title' => $this
      ->t('Theme'),
    '#maxlength' => 255,
    '#default_value' => $default,
    '#description' => $this
      ->t("Drupal Theme associated with this Mega Menu."),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'value',
    '#value' => '',
  ];
  $form['block_config'] = [
    '#type' => 'value',
    '#value' => Json::encode([]),
  ];
  $form['menu_config'] = [
    '#type' => 'value',
    '#value' => Json::encode([]),
  ];

  // You will need additional form elements for your custom properties.
  return $form;
}