function book_prev
book_prev($book_link)
Fetches the menu link for the previous page of the book.
Parameters
$book_link: A fully loaded menu link that is part of the book hierarchy.
Return value
A fully loaded menu link for the page before the one represented in $book_link.
File
- modules/book/book.module, line 765
- Allows users to create and organize related content in an outline.
Code
function book_prev($book_link) { // If the parent is zero, we are at the start of a book. if ($book_link['plid'] == 0) { return NULL; } $flat = book_get_flat_menu($book_link); // Assigning the array to $flat resets the array pointer for use with each(). $curr = NULL; do { $prev = $curr; list($key, $curr) = each($flat); } while ($key && $key != $book_link['mlid']); if ($key == $book_link['mlid']) { // The previous page in the book may be a child of the previous visible link. if ($prev['depth'] == $book_link['depth'] && $prev['has_children']) { // The subtree will have only one link at the top level - get its data. $tree = book_menu_subtree_data($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']); } return $data['link']; } else { return $prev; } } }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!book!book.module/function/book_prev/7.x