You are here

protected function MenuItemParser::childTree in Menu Firstchild 2.x

Same name and namespace in other branches
  1. 8 src/MenuItemParser.php \Drupal\menu_firstchild\MenuItemParser::childTree()

Returns the URL of the first child of given menu item.

This does take into account menu_firstchild.

Parameters

array $item: Menu item array.

string $menu_name: Menu machine name.

Return value

array Menu tree below current item.

2 calls to MenuItemParser::childTree()
MenuItemParser::firstChildUrl in src/MenuItemParser.php
Returns the URL of the first child of given menu item.
MenuItemParser::parse in src/MenuItemParser.php
Parses a menu item and modifies it if menu_firstchild is enabled.

File

src/MenuItemParser.php, line 119

Class

MenuItemParser
Class MenuItemParser.

Namespace

Drupal\menu_firstchild

Code

protected function childTree(array $item, $menu_name) {

  // Init menu tree.
  $menu_tree = \Drupal::menuTree();

  // Get parameters of given link.
  $id = $item['original_link']
    ->getPluginId();
  $parameters = new MenuTreeParameters();
  $parameters
    ->setRoot($id)
    ->excludeRoot()
    ->setMaxDepth(1)
    ->onlyEnabledLinks();

  // Load the tree based on this set of parameters.
  $tree = $menu_tree
    ->load($menu_name, $parameters);

  // Transform the tree.
  $manipulators = [
    // Only show links that are accessible for the current user.
    [
      'callable' => 'menu.default_tree_manipulators:checkAccess',
    ],
    // Use the default sorting of menu links.
    [
      'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
    ],
  ];

  // Get tree.
  $tree = $menu_tree
    ->transform($tree, $manipulators);
  return $tree;
}