diff --git a/core/modules/book/book.module b/core/modules/book/book.module index 9eecf7a..925547c 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -237,7 +237,7 @@ function _book_outline_access(EntityInterface $node) { * @see book_menu() */ function _book_outline_remove_access(EntityInterface $node) { - return Drupal::service('book.manager')->nodeIsRemovable($node) + return Drupal::service('book.manager')->checkNodeIsRemovable($node) && _book_outline_access($node); } @@ -637,7 +637,7 @@ function book_node_prepare_form(NodeInterface $node, $form_display, $operation, } // Set defaults. $node_ref = !$node->isNew() ? $node->id() : 'new'; - $node->book += $book_manager->linkDefaults($node_ref); + $node->book += $book_manager->getLinkDefaults($node_ref); } else { if (isset($node->book['bid']) && !isset($node->book['original_bid'])) { @@ -646,7 +646,7 @@ function book_node_prepare_form(NodeInterface $node, $form_display, $operation, } // Find the depth limit for the parent select. if (isset($node->book['bid']) && !isset($node->book['parent_depth_limit'])) { - $node->book['parent_depth_limit'] = $book_manager->parentDepthLimit($node->book); + $node->book['parent_depth_limit'] = $book_manager->getParentDepthLimit($node->book); } } diff --git a/core/modules/book/book.pages.inc b/core/modules/book/book.pages.inc index 32c7852..40e44b2 100644 --- a/core/modules/book/book.pages.inc +++ b/core/modules/book/book.pages.inc @@ -50,7 +50,7 @@ function book_remove_form($form, &$form_state, EntityInterface $node) { */ function book_remove_form_submit($form, &$form_state) { $node = $form['#node']; - if (Drupal::service('book.manager')->nodeIsRemovable($node)) { + if (Drupal::service('book.manager')->checkNodeIsRemovable($node)) { menu_link_delete($node->book['mlid']); db_delete('book') ->condition('nid', $node->id()) diff --git a/core/modules/book/lib/Drupal/book/BookManager.php b/core/modules/book/lib/Drupal/book/BookManager.php index 2a6834d..f10630b 100644 --- a/core/modules/book/lib/Drupal/book/BookManager.php +++ b/core/modules/book/lib/Drupal/book/BookManager.php @@ -123,7 +123,7 @@ protected function loadBooks() { * @return array * The default values for the menu link. */ - public function linkDefaults($nid) { + public function getLinkDefaults($nid) { return array( 'original_bid' => 0, 'menu_name' => '', @@ -148,7 +148,7 @@ public function linkDefaults($nid) { * @return int * The depth limit for items in the parent select. */ - public function parentDepthLimit($book_link) { + public function getParentDepthLimit(array $book_link) { return MENU_MAX_DEPTH - 1 - (($book_link['mlid'] && $book_link['has_children']) ? $this->entityManager->getStorageController('menu_link')->findChildrenRelativeDepth($book_link) : 0); } @@ -258,7 +258,7 @@ public function addFormElements(array $form, array &$form_state, NodeInterface $ * @return bool * TRUE if a node can be removed from the book, FALSE otherwise. */ - public function nodeIsRemovable(NodeInterface $node) { + public function checkNodeIsRemovable(NodeInterface $node) { return (!empty($node->book['bid']) && (($node->book['bid'] != $node->id()) || !$node->book['has_children'])); } @@ -316,8 +316,6 @@ public function updateOutline(NodeInterface $node) { 'bid' => $node->book['bid'], )) ->execute(); - // Reset the cache of stored books. - drupal_static_reset('book_get_books'); } else { if ($node->book['bid'] != $this->connection->query("SELECT bid FROM {book} WHERE nid = :nid", array( @@ -325,8 +323,6 @@ public function updateOutline(NodeInterface $node) { ))->fetchField()) { // Update the bid for this page and all children. $this->updateID($node->book); - // Reset the cache of stored books. - drupal_static_reset('book_get_books'); } } @@ -380,7 +376,7 @@ public function createMenuName($id) { * @param array $book_link * A fully loaded menu link that is part of the book hierarchy. */ - function updateID($book_link) { + public function updateID(array $book_link) { $query = $this->connection->select('menu_links'); $query->addField('menu_links', 'mlid'); for ($i = 1; $i <= MENU_MAX_DEPTH && $book_link["p$i"]; $i++) { @@ -409,7 +405,7 @@ function updateID($book_link) { * @return array * A parent selection form element. */ - function addParentSelectFormElements($book_link) { + protected function addParentSelectFormElements(array $book_link) { if ($this->configFactory->get('menu.settings')->get('override_parent_selector')) { return array(); } @@ -471,7 +467,7 @@ function addParentSelectFormElements($book_link) { * @param int $depth_limit * Any link deeper than this value will be excluded (along with its children). */ - protected function recurseTableOfContents($tree, $indent, &$toc, $exclude, $depth_limit) { + protected function recurseTableOfContents(array $tree, $indent, array &$toc, array $exclude, $depth_limit) { foreach ($tree as $data) { if ($data['link']['depth'] > $depth_limit) { // Don't iterate through any links on this level. @@ -503,7 +499,7 @@ protected function recurseTableOfContents($tree, $indent, &$toc, $exclude, $dept * An array of (menu link ID, title) pairs for use as options for selecting a * book page. */ - public function getTableOfContents($bid, $depth_limit, $exclude = array()) { + public function getTableOfContents($bid, $depth_limit, array $exclude = array()) { $tree = menu_tree_all_data($this->createMenuName($bid)); $toc = array(); $this->recurseTableOfContents($tree, '', $toc, $exclude, $depth_limit); diff --git a/core/modules/book/lib/Drupal/book/Form/BookOutlineForm.php b/core/modules/book/lib/Drupal/book/Form/BookOutlineForm.php index b60ef0f..549fb04 100644 --- a/core/modules/book/lib/Drupal/book/Form/BookOutlineForm.php +++ b/core/modules/book/lib/Drupal/book/Form/BookOutlineForm.php @@ -62,7 +62,7 @@ public function form(array $form, array &$form_state) { if (!isset($this->entity->book)) { // The node is not part of any book yet - set default options. - $this->entity->book = $this->bookManager->linkDefaults($this->entity->id()); + $this->entity->book = $this->bookManager->getLinkDefaults($this->entity->id()); } else { $this->entity->book['original_bid'] = $this->entity->book['bid']; @@ -70,7 +70,7 @@ public function form(array $form, array &$form_state) { // Find the depth limit for the parent select. if (!isset($this->entity->book['parent_depth_limit'])) { - $this->entity->book['parent_depth_limit'] = $this->bookManager->parentDepthLimit($this->entity->book); + $this->entity->book['parent_depth_limit'] = $this->bookManager->getParentDepthLimit($this->entity->book); } $form = $this->bookManager->addFormElements($form, $form_state, $this->entity, $this->getCurrentUser()); @@ -84,7 +84,7 @@ protected function actions(array $form, array &$form_state) { $actions = parent::actions($form, $form_state); $actions['submit']['#value'] = $this->entity->book['original_bid'] ? $this->t('Update book outline') : $this->t('Add to book outline'); $actions['delete']['#value'] = $this->t('Remove from book outline'); - $actions['delete']['#access'] = $this->bookManager->nodeIsRemovable($this->entity); + $actions['delete']['#access'] = $this->bookManager->checkNodeIsRemovable($this->entity); return $actions; }