function BookManager::moveChildren
Same name in other branches
- 9 core/modules/book/src/BookManager.php \Drupal\book\BookManager::moveChildren()
- 8.9.x core/modules/book/src/BookManager.php \Drupal\book\BookManager::moveChildren()
- 10 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
File
-
core/
modules/ book/ src/ BookManager.php, line 897
Class
- BookManager
- Defines a book manager.
Namespace
Drupal\bookCode
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);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.