function BookManager::doBookTreeCheckAccess

Same name in other branches
  1. 9 core/modules/book/src/BookManager.php \Drupal\book\BookManager::doBookTreeCheckAccess()
  2. 8.9.x core/modules/book/src/BookManager.php \Drupal\book\BookManager::doBookTreeCheckAccess()
  3. 11.x 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

File

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

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;
}

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