DefaultMenuLinkTreeManipulators::generateIndexAndSort

public DefaultMenuLinkTreeManipulators::generateIndexAndSort(array $tree)

Generates a unique index and sorts by it.

Parameters

\Drupal\Core\Menu\MenuLinkTreeElement[] $tree: The menu link tree to manipulate.

Return value

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

File

core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php, line 226

Class

DefaultMenuLinkTreeManipulators
Provides a couple of menu link tree manipulators.

Namespace

Drupal\Core\Menu

Code

public function generateIndexAndSort(array $tree) {
  $new_tree = array();
  foreach ($tree as $key => $v) {
    if ($tree[$key]->subtree) {
      $tree[$key]->subtree = $this->generateIndexAndSort($tree[$key]->subtree);
    }
    $instance = $tree[$key]->link;
    // The weights are made a uniform 5 digits by adding 50000 as an offset.
    // After $this->menuLinkCheckAccess(), $instance->getTitle() has the
    // localized or translated title. Adding the plugin id to the end of the
    // index insures that it is unique.
    $new_tree[(50000 + $instance->getWeight()) . ' ' . $instance->getTitle() . ' ' . $instance->getPluginId()] = $tree[$key];
  }
  ksort($new_tree);
  return $new_tree;
}
doc_Drupal
2016-10-29 09:01:48
Comments
Leave a Comment

Please login to continue.