You are here

protected function MenuForm::buildOverviewForm in Colossal Menu 8

Same name and namespace in other branches
  1. 2.x src/Form/MenuForm.php \Drupal\colossal_menu\Form\MenuForm::buildOverviewForm()

Form constructor to edit an entire menu tree at once.

Shows for one menu the menu links accessible to the current user and relevant operations.

This form constructor can be integrated as a section into another form. It relies on the following keys in $form_state:

  • menu: A menu entity.
  • menu_overview_form_parents: An array containing the parent keys to this form.

Forms integrating this section should call menu_overview_form_submit() from their form submit handler.

1 call to MenuForm::buildOverviewForm()
MenuForm::form in src/Form/MenuForm.php
Gets the actual form array to be built.

File

src/Form/MenuForm.php, line 181

Class

MenuForm
Settings form for menus.

Namespace

Drupal\colossal_menu\Form

Code

protected function buildOverviewForm(array &$form, FormStateInterface $form_state) {
  $menu = $this->entity;

  // Ensure that menu_overview_form_submit() knows the parents of this form
  // section.
  if (!$form_state
    ->has('menu_overview_form_parents')) {
    $form_state
      ->set('menu_overview_form_parents', []);
  }
  $form['links'] = [
    '#type' => 'table',
    '#sorted' => TRUE,
    '#header' => [
      $this
        ->t('Title'),
      $this
        ->t('Enabled'),
      $this
        ->t('Weight'),
      [
        'data' => $this
          ->t('Operations'),
        'colspan' => 3,
      ],
    ],
    '#tabledrag' => [
      [
        'action' => 'match',
        'relationship' => 'parent',
        'group' => 'link-parent',
        'subgroup' => 'link-parent',
        'source' => 'link-id',
        'hidden' => TRUE,
        'limit' => $this->menuLinkTree
          ->maxDepth(),
      ],
      [
        'action' => 'order',
        'relationship' => 'sibling',
        'group' => 'link-weight',
      ],
    ],
  ];
  $params = new MenuTreeParameters();
  $tree = $this->menuLinkTree
    ->load($menu
    ->id(), $params);
  $elements = [];
  foreach ($tree as $item) {
    $this
      ->buildLinkElement($elements, $item);
  }
  $form['links'] = $form['links'] + $elements;
  return $form;
}