You are here

public function BigMenuForm::processLinks in Big Menu 8

Same name and namespace in other branches
  1. 2.x src/BigMenuForm.php \Drupal\bigmenu\BigMenuForm::processLinks()

Format the links appropriately so draggable views will work.

Parameters

array $form: The form array.

array $links: An array of links.

string $menu_link: A menu link plugin id.

1 call to BigMenuForm::processLinks()
BigMenuForm::buildOverviewFormWithDepth in src/BigMenuForm.php
Build a shallow version of the overview form.

File

src/BigMenuForm.php, line 185

Class

BigMenuForm
Defines class for BigMenuForm.

Namespace

Drupal\bigmenu

Code

public function processLinks(array &$form, array &$links, $menu_link) {
  foreach (Element::children($links) as $id) {
    if (isset($links[$id]['#item'])) {
      $element = $links[$id];
      $form['links'][$id]['#item'] = $element['#item'];

      // TableDrag: Mark the table row as draggable.
      $form['links'][$id]['#attributes'] = $element['#attributes'];
      $form['links'][$id]['#attributes']['class'][] = 'draggable';

      // TableDrag: Sort the table row according to its existing/configured
      // weight.
      $form['links'][$id]['#weight'] = $element['#item']->link
        ->getWeight();

      // Add special classes to be used for tabledrag.js.
      $element['parent']['#attributes']['class'] = [
        'menu-parent',
      ];
      $element['weight']['#attributes']['class'] = [
        'menu-weight',
      ];
      $element['id']['#attributes']['class'] = [
        'menu-id',
      ];
      $form['links'][$id]['title'] = [
        [
          '#theme' => 'indentation',
          '#size' => $element['#item']->depth - 1,
        ],
        $element['title'],
      ];
      $form['links'][$id]['root'][] = [];

      // The hasChildren property only checks enabled children. The link
      // to edit children should be available when all children are not
      // enabled, so perform an additional check when necessary.
      // @see https://www.drupal.org/node/2302149
      if ($form['links'][$id]['#item']->hasChildren || $this
        ->hasAnyChildren($links[$id]['#item'])) {
        if (is_null($menu_link) || isset($menu_link) && $menu_link != $element['#item']->link
          ->getPluginId()) {
          $uri = $this->entity
            ->toUrl('edit-form', [
            'query' => [
              'menu_link' => $element['#item']->link
                ->getPluginId(),
            ],
          ]);
          $form['links'][$id]['root'][] = [
            '#type' => 'link',
            '#title' => $this
              ->t('Edit child items'),
            '#url' => $uri,
          ];
        }
      }
      $form['links'][$id]['enabled'] = $element['enabled'];
      $form['links'][$id]['enabled']['#wrapper_attributes']['class'] = [
        'checkbox',
        'menu-enabled',
      ];
      $form['links'][$id]['weight'] = $element['weight'];

      // Operations (dropbutton) column.
      $form['links'][$id]['operations'] = $element['operations'];
      $form['links'][$id]['id'] = $element['id'];
      $form['links'][$id]['parent'] = $element['parent'];
    }
  }
}