diff --git a/core/modules/book/book.module b/core/modules/book/book.module index 21f9bb0..a88492b 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -185,35 +185,6 @@ function book_menu() { } /** - * Access callback: Determines if the outline tab is accessible. - * - * Path: - * - admin/structure/book/%node - * - node/%node/outline - * - * @param \Drupal\Core\Entity\EntityInterface $node - * The node whose outline tab is to be viewed. - * - * @see book_menu() - */ -function _book_outline_access(EntityInterface $node) { - return \Drupal::currentUser()->hasPermission('administer book outlines') && node_access('view', $node); -} - -/** - * Access callback: Determines if the user can remove nodes from the outline. - * - * @param \Drupal\Core\Entity\EntityInterface $node - * The node to remove from the outline. - * - * @see book_menu() - */ -function _book_outline_remove_access(EntityInterface $node) { - return \Drupal::service('book.manager')->checkNodeIsRemovable($node) - && _book_outline_access($node); -} - -/** * Implements hook_admin_paths(). */ function book_admin_paths() { diff --git a/core/modules/book/book.pages.inc b/core/modules/book/book.pages.inc deleted file mode 100644 index d01636c..0000000 --- a/core/modules/book/book.pages.inc +++ /dev/null @@ -1,56 +0,0 @@ - $node->label()); - - if ($node->book['has_children']) { - $description = t('%title has associated child pages, which will be relocated automatically to maintain their connection to the book. To recreate the hierarchy (as it was before removing this page), %title may be added again using the Outline tab, and each of its former child pages will need to be relocated manually.', $title); - } - else { - $description = t('%title may be added to hierarchy again using the Outline tab.', $title); - } - - return confirm_form($form, t('Are you sure you want to remove %title from the book hierarchy?', $title), 'node/' . $node->id(), $description, t('Remove')); -} - -/** - * Form submission handler for book_remove_form(). - */ -function book_remove_form_submit($form, &$form_state) { - $node = $form['#node']; - if (\Drupal::service('book.manager')->checkNodeIsRemovable($node)) { - menu_link_delete($node->book['mlid']); - db_delete('book') - ->condition('nid', $node->id()) - ->execute(); - drupal_set_message(t('The post has been removed from the book.')); - } - $form_state['redirect_route'] = array( - 'route_name' => 'node.view', - 'route_parameters' => array( - 'node' => $node->id(), - ), - ); -} diff --git a/core/modules/book/book.routing.yml b/core/modules/book/book.routing.yml index 1ce1e82..496740e 100644 --- a/core/modules/book/book.routing.yml +++ b/core/modules/book/book.routing.yml @@ -48,7 +48,7 @@ book.admin_edit: book.remove: path: '/node/{node}/outline/remove' defaults: - _content: '\Drupal\book\Form\BookForm::remove' + _form: '\Drupal\book\Form\BookRemoveForm' _title: 'Remove from outline' options: _access_mode: 'ALL' diff --git a/core/modules/book/lib/Drupal/book/BookManager.php b/core/modules/book/lib/Drupal/book/BookManager.php index d246632..3bb4e8b 100644 --- a/core/modules/book/lib/Drupal/book/BookManager.php +++ b/core/modules/book/lib/Drupal/book/BookManager.php @@ -493,4 +493,16 @@ public function getTableOfContents($bid, $depth_limit, array $exclude = array()) return $toc; } + /** + * Deletes node's entry form book table. + * + * @param int $nid + * The nid to delete. + */ + public function deleteBook($nid) { + $this->connection->delete('book') + ->condition('nid', $nid) + ->execute(); + } + } diff --git a/core/modules/book/lib/Drupal/book/Form/BookForm.php b/core/modules/book/lib/Drupal/book/Form/BookForm.php deleted file mode 100644 index c69ecd6..0000000 --- a/core/modules/book/lib/Drupal/book/Form/BookForm.php +++ /dev/null @@ -1,26 +0,0 @@ -bookManager = $book_manager; + $this->menuLinkStorage = $menu_link_storage; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('book.manager'), + $container->get('entity.manager')->getStorageController('menu_link') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormId() { + return 'book_remove_form'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state, NodeInterface $node = NULL) { + $this->node = $node; + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function getDescription() { + $title = array('%title' => $this->node->label()); + if ($this->node->book['has_children']) { + return $this->t('%title has associated child pages, which will be relocated automatically to maintain their connection to the book. To recreate the hierarchy (as it was before removing this page), %title may be added again using the Outline tab, and each of its former child pages will need to be relocated manually.', $title); + } + else { + return $this->t('%title may be added to hierarchy again using the Outline tab.', $title); + } + } + + /** + * {@inheritdoc} + */ + public function getConfirmText() { + return $this->t('Remove'); + } + + /** + * {@inheritdoc} + */ + public function getQuestion() { + return $this->t('Are you sure you want to remove %title from the book hierarchy?', array('%title' => $this->node->label())); + } + + /** + * {@inheritdoc} + */ + public function getCancelRoute() { + return array( + 'route_name' => 'node.view', + 'route_parameters' => array( + 'node' => $this->node->id(), + ), + ); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + if ($this->bookManager->checkNodeIsRemovable($this->node)) { + $menu_links = $this->menuLinkStorage->load(array($this->node->book['mlid'])); + $this->menuLinkStorage->delete($menu_links); + $this->bookManager->deleteBook($this->node->id()); + drupal_set_message($this->t('The post has been removed from the book.')); + } + $form_state['redirect_route'] = array( + 'route_name' => 'node.view', + 'route_parameters' => array( + 'node' => $this->node->id(), + ), + ); + } + +} diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageControllerInterface.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageControllerInterface.php index bc9c609..3fb408f 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageControllerInterface.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageControllerInterface.php @@ -13,7 +13,7 @@ /** * Defines a common interface for menu link entity controller classes. */ -interface MenuLinkStorageControllerInterface { +interface MenuLinkStorageControllerInterface extends EntityStorageControllerInterface { /** * Sets an internal flag that allows us to prevent the reparenting operations