public function BookManager::updateOutline in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/book/src/BookManager.php \Drupal\book\BookManager::updateOutline()
Handles additions and updates to the book outline.
This common helper function performs all additions and updates to the book outline through node addition, node editing, node deletion, or the outline tab.
Parameters
\Drupal\node\NodeInterface $node: The node that is being saved, added, deleted, or moved.
Return value
bool TRUE if the book link was saved; FALSE otherwise.
Overrides BookManagerInterface::updateOutline
1 call to BookManager::updateOutline()
- BookManager::deleteFromBook in core/
modules/ book/ src/ BookManager.php - Deletes node's entry from book table.
File
- core/
modules/ book/ src/ BookManager.php, line 252 - Contains \Drupal\book\BookManager.
Class
- BookManager
- Defines a book manager.
Namespace
Drupal\bookCode
public function updateOutline(NodeInterface $node) {
if (empty($node->book['bid'])) {
return FALSE;
}
if (!empty($node->book['bid'])) {
if ($node->book['bid'] == 'new') {
// New nodes that are their own book.
$node->book['bid'] = $node
->id();
}
elseif (!isset($node->book['original_bid'])) {
$node->book['original_bid'] = $node->book['bid'];
}
}
// Ensure we create a new book link if either the node itself is new, or the
// bid was selected the first time, so that the original_bid is still empty.
$new = empty($node->book['nid']) || empty($node->book['original_bid']);
$node->book['nid'] = $node
->id();
// Create a new book from a node.
if ($node->book['bid'] == $node
->id()) {
$node->book['pid'] = 0;
}
elseif ($node->book['pid'] < 0) {
// -1 is the default value in BookManager::addParentSelectFormElements().
// The node save should have set the bid equal to the node ID, but
// handle it here if it did not.
$node->book['pid'] = $node->book['bid'];
}
return $this
->saveBookLink($node->book, $new);
}