You are here

function book_node_delete in Drupal 7

Implements hook_node_delete().

File

modules/book/book.module, line 967
Allows users to create and organize related content in an outline.

Code

function book_node_delete($node) {
  if (!empty($node->book['bid'])) {
    if ($node->nid == $node->book['bid']) {

      // Handle deletion of a top-level post.
      $result = db_query("SELECT b.nid FROM {menu_links} ml INNER JOIN {book} b on b.mlid = ml.mlid WHERE ml.plid = :plid", array(
        ':plid' => $node->book['mlid'],
      ));
      foreach ($result as $child) {
        $child_node = node_load($child->nid);
        $child_node->book['bid'] = $child_node->nid;
        _book_update_outline($child_node);
      }
    }
    menu_link_delete($node->book['mlid']);
    db_delete('book')
      ->condition('mlid', $node->book['mlid'])
      ->execute();
    drupal_static_reset('book_get_books');
  }
}