You are here

function token_book_load_all_parents in Token 8

Loads all the parents of the book page.

Parameters

array $book: The book data. The 'nid' key points to the current page of the book. The 'p1' ... 'p9' keys point to parents of the page, if they exist, with 'p1' pointing to the book itself and the last defined pX to the current page.

Return value

string[] List of node titles of the book parents.

1 call to token_book_load_all_parents()
book_tokens in ./token.tokens.inc
Implements hook_tokens() on behalf of book.module.

File

./token.module, line 623
Enhances the token API in core: adds a browseable UI, missing tokens, etc.

Code

function token_book_load_all_parents(array $book) {
  $cache =& drupal_static(__FUNCTION__, []);
  if (empty($book['nid'])) {
    return [];
  }
  $nid = $book['nid'];
  if (!isset($cache[$nid])) {
    $cache[$nid] = [];
    $i = 1;
    while ($book["p{$i}"] != $nid) {
      $cache[$nid][] = Node::load($book["p{$i}"])
        ->getTitle();
      $i++;
    }
  }
  return $cache[$nid];
}