You are here

protected function BookManager::doBookTreeCheckAccess in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/book/src/BookManager.php \Drupal\book\BookManager::doBookTreeCheckAccess()
  2. 10 core/modules/book/src/BookManager.php \Drupal\book\BookManager::doBookTreeCheckAccess()

Sorts the menu tree and recursively checks access for each item.

Parameters

array $tree: The book tree to operate on.

1 call to BookManager::doBookTreeCheckAccess()
BookManager::bookTreeCheckAccess in core/modules/book/src/BookManager.php
Checks access and performs dynamic operations for each link in the tree.

File

core/modules/book/src/BookManager.php, line 987

Class

BookManager
Defines a book manager.

Namespace

Drupal\book

Code

protected function doBookTreeCheckAccess(&$tree) {
  $new_tree = [];
  foreach ($tree as $key => $v) {
    $item =& $tree[$key]['link'];
    $this
      ->bookLinkTranslate($item);
    if ($item['access']) {
      if ($tree[$key]['below']) {
        $this
          ->doBookTreeCheckAccess($tree[$key]['below']);
      }

      // The weights are made a uniform 5 digits by adding 50000 as an offset.
      // After calling $this->bookLinkTranslate(), $item['title'] has the
      // translated title. Adding the nid to the end of the index insures that
      // it is unique.
      $new_tree[50000 + $item['weight'] . ' ' . $item['title'] . ' ' . $item['nid']] = $tree[$key];
    }
  }

  // Sort siblings in the tree based on the weights and localized titles.
  ksort($new_tree);
  $tree = $new_tree;
}