You are here

protected function BigMenuForm::getTree in Big Menu 8

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

Gets the menu tree.

Parameters

int $depth: The depth.

string $root: An optional root menu link plugin id.

Return value

\Drupal\Core\Menu\MenuLinkTreeElement[] An array of menu link tree elements.

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

File

src/BigMenuForm.php, line 258

Class

BigMenuForm
Defines class for BigMenuForm.

Namespace

Drupal\bigmenu

Code

protected function getTree($depth, $root = NULL) {
  $tree_params = new MenuTreeParameters();
  $tree_params
    ->setMaxDepth($depth);
  if ($root) {
    $tree_params
      ->setRoot($root);
  }
  $tree = $this->menuTree
    ->load($this->entity
    ->id(), $tree_params);

  // We indicate that a menu administrator is running the menu access check.
  $this
    ->getRequest()->attributes
    ->set('_menu_admin', TRUE);
  $manipulators = [
    [
      'callable' => 'menu.default_tree_manipulators:checkAccess',
    ],
    [
      'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
    ],
  ];
  $tree = $this->menuTree
    ->transform($tree, $manipulators);
  $this
    ->getRequest()->attributes
    ->set('_menu_admin', FALSE);
  return $tree;
}