You are here

public function MenuLinkTree::transform in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Menu/MenuLinkTree.php \Drupal\Core\Menu\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:

Return value

\Drupal\Core\Menu\MenuLinkTreeElement[] The manipulated menu link tree.

Overrides MenuLinkTreeInterface::transform

File

core/lib/Drupal/Core/Menu/MenuLinkTree.php, line 135
Contains \Drupal\Core\Menu\MenuLinkTree.

Class

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

Namespace

Drupal\Core\Menu

Code

public function transform(array $tree, array $manipulators) {
  foreach ($manipulators as $manipulator) {
    $callable = $manipulator['callable'];
    $callable = $this->controllerResolver
      ->getControllerFromDefinition($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;
}