You are here

public function MenuForm::form in Colossal Menu 8

Same name and namespace in other branches
  1. 2.x src/Form/MenuForm.php \Drupal\colossal_menu\Form\MenuForm::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/MenuForm.php, line 56

Class

MenuForm
Settings form for menus.

Namespace

Drupal\colossal_menu\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $menu = $this->entity;
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $menu
      ->label(),
    '#description' => $this
      ->t("Label for the Menu."),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#default_value' => $menu
      ->id(),
    '#machine_name' => [
      'exists' => '\\Drupal\\colossal_menu\\Entity\\Menu::load',
    ],
    '#disabled' => !$menu
      ->isNew(),
  ];

  // Add menu links administration form for existing menus.
  if (!$menu
    ->isNew()) {

    // Form API supports constructing and validating self-contained sections
    // within forms, but does not allow handling the form section's submission
    // equally separated yet. Therefore, we use a $form_state key to point to
    // the parents of the form section.
    // @see self::submitOverviewForm()
    $form_state
      ->set('links', [
      'links',
    ]);
    $form['links'] = [];
    $form['links'] = $this
      ->buildOverviewForm($form['links'], $form_state);
  }
  return parent::form($form, $form_state);
}