book_nodeapi

Versions
4.6 – 6
book_nodeapi(&$node, $op, $teaser, $page)

Implementation of hook_nodeapi().

Appends book navigation to all nodes in the book.

Code

modules/book.module, line 459

<?php
function book_nodeapi(&$node, $op, $teaser, $page) {
  switch ($op) {
    case 'view':
      if (!$teaser) {
        $book = db_fetch_array(db_query('SELECT * FROM {book} WHERE vid = %d', $node->vid));
        if ($book) {
          if ($node->moderate && user_access('administer nodes')) {
            drupal_set_message(t("The post has been submitted for moderation and won't be accessible until it has been approved."));
          }

          foreach ($book as $key => $value) {
            $node->$key = $value;
          }

          $path = book_location($node);
          // Construct the breadcrumb:
          $node->breadcrumb = array(); // Overwrite the trail with a book trail.
          foreach ($path as $level) {
            $node->breadcrumb[] = array('path' => 'node/'. $level->nid, 'title' =>  $level->title);
          }
          $node->breadcrumb[] = array('path' => 'node/'. $node->nid);

          $node->body .= theme('book_navigation', $node);

          if ($page) {
            menu_set_location($node->breadcrumb);
          }
        }
      }
      break;
    case 'delete revision':
      db_query('DELETE FROM {book} WHERE vid = %d', $node->vid);
      break;
    case 'delete':
      db_query('DELETE FROM {book} WHERE nid = %d', $node->nid);
      break;
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.