You are here

protected function BookManager::moveChildren in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 806
Contains \Drupal\book\BookManager.

Class

BookManager
Defines a book manager.

Namespace

Drupal\book

Code

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