book_block

Definition

book_block($op = 'list', $delta = 0)
modules/book.module, line 129

Description

Implementation of hook_block().

Displays the book table of contents in a block when the current page is a single-node view of a book node.

Code

<?php
function book_block($op = 'list', $delta = 0) {
  $block = array();
  if ($op == 'list') {
    $block[0]['info'] = t('Book navigation');
    return $block;
  }
  else if ($op == 'view') {
    // Only display this block when the user is browsing a book:
    if (arg(0) == 'node' && is_numeric(arg(1))) {
      $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.nid = %d'), arg(1));
      if (db_num_rows($result) > 0) {
        $node = db_fetch_object($result);

        $path = book_location($node);
        $path[] = $node;

        $expand = array();
        foreach ($path as $key => $node) {
          $expand[] = $node->nid;
        }

        $block['subject'] = check_plain($path[0]->title);
        $block['content'] = book_tree($expand[0], 5, $expand);
      }
    }

    return $block;
  }
}
?>
 
 

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.