function BookManager::updateOriginalParent

Same name in other branches
  1. 9 core/modules/book/src/BookManager.php \Drupal\book\BookManager::updateOriginalParent()
  2. 8.9.x core/modules/book/src/BookManager.php \Drupal\book\BookManager::updateOriginalParent()
  3. 11.x 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
BookManager::saveBookLink in core/modules/book/src/BookManager.php

File

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

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'], [
        'has_children' => $parent_has_children,
    ]);
}

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