You are here

protected function BookManager::moveChildren in Drupal 9

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

Moves children from the original parent to the updated link.

Parameters

array $link: The link being saved.

array $original: The original parent of $link.

1 call to BookManager::moveChildren()
BookManager::saveBookLink in core/modules/book/src/BookManager.php
Saves a single book entry.

File

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

Class

BookManager
Defines a book manager.

Namespace

Drupal\book

Code

protected function moveChildren(array $link, array $original) {
  $p = 'p1';
  $expressions = [];
  for ($i = 1; $i <= $link['depth']; $p = 'p' . ++$i) {
    $expressions[] = [
      $p,
      ":p_{$i}",
      [
        ":p_{$i}" => $link[$p],
      ],
    ];
  }
  $j = $original['depth'] + 1;
  while ($i <= static::BOOK_MAX_DEPTH && $j <= static::BOOK_MAX_DEPTH) {
    $expressions[] = [
      'p' . $i++,
      'p' . $j++,
      [],
    ];
  }
  while ($i <= static::BOOK_MAX_DEPTH) {
    $expressions[] = [
      'p' . $i++,
      0,
      [],
    ];
  }
  $shift = $link['depth'] - $original['depth'];
  if ($shift > 0) {

    // The order of expressions must be reversed so the new values don't
    // overwrite the old ones before they can be used because "Single-table
    // UPDATE assignments are generally evaluated from left to right".
    // @see http://dev.mysql.com/doc/refman/5.0/en/update.html
    $expressions = array_reverse($expressions);
  }
  $this->bookOutlineStorage
    ->updateMovedChildren($link['bid'], $original, $expressions, $shift);
}