You are here

function book_helper_nodeapi in Book helper 6

Implementation of hook_nodeapi().

File

./book_helper.module, line 95
Improves Drupal's core book module's functionality.

Code

function book_helper_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'view':

      // Remove book navigation.
      if (variable_get('book_helper_remove_book_navigation', 0) == 1) {
        unset($node->content['book_navigation']);
      }
      break;
    case 'load':

      // Track customized link title and whether it is sync (equal) to the node's title.
      $link_title = db_result(db_query('SELECT link_title FROM {book} b INNER JOIN {menu_links} ml ON b.mlid = ml.mlid WHERE b.nid = %d', $node->nid));
      if ($link_title) {
        $node_title = function_exists('node_parent_title_remove') ? node_parent_title_remove($node->title) : $node->title;
        $info['book_helper']['link_title_custom'] = $link_title;
        $info['book_helper']['link_title_sync'] = $link_title == $node_title ? TRUE : FALSE;
        return $info;
      }
      break;
    case 'insert':
    case 'update':

      // Get link title sync and custom from the book.module's array().
      if (isset($node->book['book_helper_link_title_sync'])) {
        $node->book_helper['link_title_sync'] = $node->book['book_helper_link_title_sync'];
      }
      if (isset($node->book['book_helper_link_title_custom'])) {
        $node->book_helper['link_title_custom'] = $node->book['book_helper_link_title_custom'];
      }

      // Update the book page's menu link title if it has been customized.
      if (!empty($node->book['bid']) && empty($node->book_helper['link_title_sync']) && $node->book_helper['link_title_custom'] != $node->book['link_title']) {
        db_query("UPDATE {menu_links} SET link_title='%s' WHERE mlid = %d", $node->book_helper['link_title_custom'], $node->book['mlid']);
      }
      break;
    default:
      break;
  }
}