function _book_update_outline in Drupal 6
Same name and namespace in other branches
- 7 modules/book/book.module \_book_update_outline()
Common helper function to handles additions and updates to the book outline.
Performs all additions and updates to the book outline through node addition, node editing, node deletion, or the outline tab.
2 calls to _book_update_outline()
- book_nodeapi in modules/
book/ book.module - Implementation of hook_nodeapi().
- book_outline_form_submit in modules/
book/ book.pages.inc - Handles book outline form submissions from the outline tab.
File
- modules/
book/ book.module, line 438 - Allows users to structure the pages of a site in a hierarchy or outline.
Code
function _book_update_outline(&$node) {
if (empty($node->book['bid'])) {
return FALSE;
}
$new = empty($node->book['mlid']);
$node->book['link_path'] = 'node/' . $node->nid;
$node->book['link_title'] = $node->title;
$node->book['parent_mismatch'] = FALSE;
// The normal case.
if ($node->book['bid'] == $node->nid) {
$node->book['plid'] = 0;
$node->book['menu_name'] = book_menu_name($node->nid);
}
else {
// Check in case the parent is not is this book; the book takes precedence.
if (!empty($node->book['plid'])) {
$parent = db_fetch_array(db_query("SELECT * FROM {book} WHERE mlid = %d", $node->book['plid']));
}
if (empty($node->book['plid']) || !$parent || $parent['bid'] != $node->book['bid']) {
$node->book['plid'] = db_result(db_query("SELECT mlid FROM {book} WHERE nid = %d", $node->book['bid']));
$node->book['parent_mismatch'] = TRUE;
// Likely when JS is disabled.
}
}
if (menu_link_save($node->book)) {
if ($new) {
// Insert new.
db_query("INSERT INTO {book} (nid, mlid, bid) VALUES (%d, %d, %d)", $node->nid, $node->book['mlid'], $node->book['bid']);
}
else {
if ($node->book['bid'] != db_result(db_query("SELECT bid FROM {book} WHERE nid = %d", $node->nid))) {
// Update the bid for this page and all children.
book_update_bid($node->book);
}
}
return TRUE;
}
// Failed to save the menu link
return FALSE;
}