1 book.module book_node_predelete(Node $node)

Implements hook_node_predelete().

File

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

Code

function book_node_predelete(Node $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();
    backdrop_static_reset('book_get_books');
  }
}