function book_prev in Drupal 6
Same name and namespace in other branches
- 4 modules/book.module \book_prev()
- 5 modules/book/book.module \book_prev()
- 7 modules/book/book.module \book_prev()
Fetches the menu link for the previous page of the book.
1 call to book_prev()
- template_preprocess_book_navigation in modules/
book/ book.module - Process variables for book-navigation.tpl.php.
File
- modules/
book/ book.module, line 542 - Allows users to structure the pages of a site in a hierarchy or 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.
$data = array_shift(book_menu_subtree_data($prev));
// 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;
}
}
}