function BookManager::updateOutline

Same name in this branch
  1. 10 core/modules/book/src/ProxyClass/BookManager.php \Drupal\book\ProxyClass\BookManager::updateOutline()
Same name in other branches
  1. 9 core/modules/book/src/BookManager.php \Drupal\book\BookManager::updateOutline()
  2. 8.9.x core/modules/book/src/BookManager.php \Drupal\book\BookManager::updateOutline()
  3. 11.x core/modules/book/src/ProxyClass/BookManager.php \Drupal\book\ProxyClass\BookManager::updateOutline()
  4. 11.x core/modules/book/src/BookManager.php \Drupal\book\BookManager::updateOutline()
1 call to BookManager::updateOutline()
BookManager::deleteFromBook in core/modules/book/src/BookManager.php

File

core/modules/book/src/BookManager.php, line 306

Class

BookManager
Defines a book manager.

Namespace

Drupal\book

Code

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'];
    }
    // Prevent changes to the book outline if the node being saved is not the
    // default revision.
    $updated = FALSE;
    if (!$new) {
        $original = $this->loadBookLink($node->id(), FALSE);
        if ($node->book['bid'] != $original['bid'] || $node->book['pid'] != $original['pid'] || $node->book['weight'] != $original['weight']) {
            $updated = TRUE;
        }
    }
    if (($new || $updated) && !$node->isDefaultRevision()) {
        return FALSE;
    }
    return $this->saveBookLink($node->book, $new);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.