function MenuLinkTree::transform
Applies menu link tree manipulators to transform the given tree.
Parameters
\Drupal\Core\Menu\MenuLinkTreeElement[] $tree: The menu tree to manipulate.
array $manipulators: The menu link tree manipulators to apply. Each is an array with keys:
- callable: a callable or a string that can be resolved to a callable by Drupal\Core\Utility\CallableResolver::getCallableFromDefinition()
- args: optional array of arguments to pass to the callable after $tree.
For example, to sort and check access:
$manipulators = [
  [
    'callable' => 'menu.default_tree_manipulators:checkNodeAccess',
  ],
  [
    'callable' => 'menu.default_tree_manipulators:checkAccess',
  ],
  [
    'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
  ],
];Return value
\Drupal\Core\Menu\MenuLinkTreeElement[] The manipulated menu link tree.
Overrides MenuLinkTreeInterface::transform
1 call to MenuLinkTree::transform()
- NavigationMenuLinkTree::transform in core/modules/ navigation/ src/ Menu/ NavigationMenuLinkTree.php 
1 method overrides MenuLinkTree::transform()
- NavigationMenuLinkTree::transform in core/modules/ navigation/ src/ Menu/ NavigationMenuLinkTree.php 
File
- 
              core/lib/ Drupal/ Core/ Menu/ MenuLinkTree.php, line 104 
Class
- MenuLinkTree
- Implements the loading, transforming and rendering of menu link trees.
Namespace
Drupal\Core\MenuCode
public function transform(array $tree, array $manipulators) {
  foreach ($manipulators as $manipulator) {
    $callable = $this->callableResolver
      ->getCallableFromDefinition($manipulator['callable']);
    // Prepare the arguments for the menu tree manipulator callable; the first
    // argument is always the menu link tree.
    if (isset($manipulator['args'])) {
      array_unshift($manipulator['args'], $tree);
      $tree = call_user_func_array($callable, $manipulator['args']);
    }
    else {
      $tree = call_user_func($callable, $tree);
    }
  }
  return $tree;
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
