function MenuLinkTree::createInstances

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Menu/MenuLinkTree.php \Drupal\Core\Menu\MenuLinkTree::createInstances()
  2. 10 core/lib/Drupal/Core/Menu/MenuLinkTree.php \Drupal\Core\Menu\MenuLinkTree::createInstances()
  3. 11.x core/lib/Drupal/Core/Menu/MenuLinkTree.php \Drupal\Core\Menu\MenuLinkTree::createInstances()

Returns a tree containing of MenuLinkTreeElement based upon tree data.

This method converts the tree representation as array coming from the tree storage to a tree containing a list of MenuLinkTreeElement[].

Parameters

array $data_tree: The tree data coming from the menu tree storage.

Return value

\Drupal\Core\Menu\MenuLinkTreeElement[] An array containing the elements of a menu tree.

1 call to MenuLinkTree::createInstances()
MenuLinkTree::load in core/lib/Drupal/Core/Menu/MenuLinkTree.php
Loads a menu tree with a menu link plugin instance at each element.

File

core/lib/Drupal/Core/Menu/MenuLinkTree.php, line 117

Class

MenuLinkTree
Implements the loading, transforming and rendering of menu link trees.

Namespace

Drupal\Core\Menu

Code

protected function createInstances(array $data_tree) {
    $tree = [];
    foreach ($data_tree as $key => $element) {
        $subtree = $this->createInstances($element['subtree']);
        // Build a MenuLinkTreeElement out of the menu tree link definition:
        // transform the tree link definition into a link definition and store
        // tree metadata.
        $tree[$key] = new MenuLinkTreeElement($this->menuLinkManager
            ->createInstance($element['definition']['id']), (bool) $element['has_children'], (int) $element['depth'], (bool) $element['in_active_trail'], $subtree);
    }
    return $tree;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.