You are here

protected function BookManager::updateOriginalParent in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/book/src/BookManager.php \Drupal\book\BookManager::updateOriginalParent()

Updates the has_children flag of the parent of the original node.

This method is called when a book link is moved or deleted. So we want to update the has_children flag of the parent node.

Parameters

array $original: The original link whose parent we want to update.

Return value

bool TRUE if the update was successful (either there was no original parent to update, or the original parent was updated successfully), FALSE on failure.

2 calls to BookManager::updateOriginalParent()
BookManager::deleteFromBook in core/modules/book/src/BookManager.php
Deletes node's entry from book table.
BookManager::saveBookLink in core/modules/book/src/BookManager.php
Saves a single book entry.

File

core/modules/book/src/BookManager.php, line 868
Contains \Drupal\book\BookManager.

Class

BookManager
Defines a book manager.

Namespace

Drupal\book

Code

protected function updateOriginalParent(array $original) {
  if ($original['pid'] == 0) {

    // There were no parents of this link. Nothing to update.
    return TRUE;
  }

  // Check if $original had at least one child.
  $original_number_of_children = $this->bookOutlineStorage
    ->countOriginalLinkChildren($original);
  $parent_has_children = (bool) $original_number_of_children ? 1 : 0;

  // Update the parent. If the original link did not have children, then the
  // parent now does not have children. If the original had children, then the
  // the parent has children now (still).
  return $this->bookOutlineStorage
    ->update($original['pid'], array(
    'has_children' => $parent_has_children,
  ));
}