function BookManager::bookLinkTranslate

Same name in other branches
  1. 9 core/modules/book/src/BookManager.php \Drupal\book\BookManager::bookLinkTranslate()
  2. 10 core/modules/book/src/ProxyClass/BookManager.php \Drupal\book\ProxyClass\BookManager::bookLinkTranslate()
  3. 10 core/modules/book/src/BookManager.php \Drupal\book\BookManager::bookLinkTranslate()
  4. 11.x core/modules/book/src/ProxyClass/BookManager.php \Drupal\book\ProxyClass\BookManager::bookLinkTranslate()
  5. 11.x core/modules/book/src/BookManager.php \Drupal\book\BookManager::bookLinkTranslate()

Overrides BookManagerInterface::bookLinkTranslate

2 calls to BookManager::bookLinkTranslate()
BookManager::doBookTreeCheckAccess in core/modules/book/src/BookManager.php
Sorts the menu tree and recursively checks access for each item.
BookManager::loadBookLinks in core/modules/book/src/BookManager.php
Loads multiple book entries.

File

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

Class

BookManager
Defines a book manager.

Namespace

Drupal\book

Code

public function bookLinkTranslate(&$link) {
    $node = NULL;
    // Access will already be set in the tree functions.
    if (!isset($link['access'])) {
        $node = $this->entityTypeManager
            ->getStorage('node')
            ->load($link['nid']);
        $link['access'] = $node && $node->access('view');
    }
    // For performance, don't localize a link the user can't access.
    if ($link['access']) {
        // @todo - load the nodes en-mass rather than individually.
        if (!$node) {
            $node = $this->entityTypeManager
                ->getStorage('node')
                ->load($link['nid']);
        }
        // The node label will be the value for the current user's language.
        $link['title'] = $node->label();
        $link['options'] = [];
    }
    return $link;
}

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