You are here

function book_made_simple_node_insert in Book made simple 7.3

Implements hook_node_insert().

File

./book_made_simple.module, line 677
Automaticly creats a book and simple creation of child pages. Author: M. Morin

Code

function book_made_simple_node_insert($node) {
  if (isset($node->book) && empty($node->book["bid"])) {
    $type = $node->type;
    $max_depth = variable_get('book_made_simple_limit_depth', 99);
    $isDepthAllowed = true;
    if (array_key_exists('depth', $node->book)) {
      $isDepthAllowed = $node->book['depth'] < $max_depth;
    }
    if ((user_access('add content to books') || user_access('administer book outlines')) && node_access('create', $type) && $isDepthAllowed) {
      $bookTypes = variable_get('book_made_simple_auto_main_page', array());
      $bookType = array_key_exists($type, $bookTypes) ? $bookTypes[$type] : null;
      $toCreate = false;
      if (null != $bookType && $bookType != "0") {
        $toCreate = true;
      }
      if ($toCreate && !isset($_GET['parent'])) {
        $node->book["bid"] = $node->nid;
        $node->book['nid'] = $node->nid;
        $node->book['module'] = 'book';
        $node->book['menu_name'] = book_menu_name($node->book['bid']);
        _book_update_outline($node);
      }
    }
  }
}