public BookManager::saveBookLink(array $link, $new)
Saves a single book entry.
Parameters
array $link: The link data to save.
bool $new: Is this a new book.
Return value
array The book data of that node.
Overrides BookManagerInterface::saveBookLink
File
- core/modules/book/src/BookManager.php, line 761
Class
- BookManager
- Defines a book manager.
Namespace
Drupal\book
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | public function saveBookLink( array $link , $new ) { // Keep track of Book IDs for cache clear. $affected_bids [ $link [ 'bid' ]] = $link [ 'bid' ]; $link += $this ->getLinkDefaults( $link [ 'nid' ]); if ( $new ) { // Insert new. $parents = $this ->getBookParents( $link , ( array ) $this ->loadBookLink( $link [ 'pid' ], FALSE)); $this ->bookOutlineStorage->insert( $link , $parents ); // Update the has_children status of the parent. $this ->updateParent( $link ); } else { $original = $this ->loadBookLink( $link [ 'nid' ], FALSE); // Using the Book ID as the key keeps this unique. $affected_bids [ $original [ 'bid' ]] = $original [ 'bid' ]; // Handle links that are moving. if ( $link [ 'bid' ] != $original [ 'bid' ] || $link [ 'pid' ] != $original [ 'pid' ]) { // Update the bid for this page and all children. if ( $link [ 'pid' ] == 0) { $link [ 'depth' ] = 1; $parent = array (); } // In case the form did not specify a proper PID we use the BID as new // parent. elseif (( $parent_link = $this ->loadBookLink( $link [ 'pid' ], FALSE)) && $parent_link [ 'bid' ] != $link [ 'bid' ]) { $link [ 'pid' ] = $link [ 'bid' ]; $parent = $this ->loadBookLink( $link [ 'pid' ], FALSE); $link [ 'depth' ] = $parent [ 'depth' ] + 1; } else { $parent = $this ->loadBookLink( $link [ 'pid' ], FALSE); $link [ 'depth' ] = $parent [ 'depth' ] + 1; } $this ->setParents( $link , $parent ); $this ->moveChildren( $link , $original ); // Update the has_children status of the original parent. $this ->updateOriginalParent( $original ); // Update the has_children status of the new parent. $this ->updateParent( $link ); } // Update the weight and pid. $this ->bookOutlineStorage->update( $link [ 'nid' ], array ( 'weight' => $link [ 'weight' ], 'pid' => $link [ 'pid' ], 'bid' => $link [ 'bid' ], )); } $cache_tags = []; foreach ( $affected_bids as $bid ) { $cache_tags [] = 'bid:' . $bid ; } Cache::invalidateTags( $cache_tags ); return $link ; } |
Please login to continue.