function book_prev

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.

1 call to book_prev()
template_preprocess_book_navigation in drupal/modules/book/book.module
Processes variables for book-navigation.tpl.php.

File

drupal/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;
    }
  }
}