BookOutline::prevLink

public BookOutline::prevLink(array $book_link)

Fetches the book link for the previous page of the book.

Parameters

array $book_link: A fully loaded book link that is part of the book hierarchy.

Return value

array A fully loaded book link for the page before the one represented in $book_link.

File

core/modules/book/src/BookOutline.php, line 37

Class

BookOutline
Provides handling to render the book outline.

Namespace

Drupal\book

Code

public function prevLink(array $book_link) {
  // If the parent is zero, we are at the start of a book.
  if ($book_link['pid'] == 0) {
    return NULL;
  }
  // Assigning the array to $flat resets the array pointer for use with each().
  $flat = $this->bookManager->bookTreeGetFlat($book_link);
  $curr = NULL;
  do {
    $prev = $curr;
    list($key, $curr) = each($flat);
  } while ($key && $key != $book_link['nid']);

  if ($key == $book_link['nid']) {
    // The previous page in the book may be a child of the previous visible link.
    if ($prev['depth'] == $book_link['depth']) {
      // The subtree will have only one link at the top level - get its data.
      $tree = $this->bookManager->bookSubtreeData($prev);
      $data = array_shift($tree);
      // The link of interest is the last child - iterate to find the deepest one.
      while ($data['below']) {
        $data = end($data['below']);
      }
      $this->bookManager->bookLinkTranslate($data['link']);
      return $data['link'];
    }
    else {
      $this->bookManager->bookLinkTranslate($prev);
      return $prev;
    }
  }
}
doc_Drupal
2016-10-29 08:48:19
Comments
Leave a Comment

Please login to continue.