diff --git a/core/modules/book/book.module b/core/modules/book/book.module index c316278..060fa8d 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -188,11 +188,7 @@ function book_menu() { ); $items['node/%node/outline/remove'] = array( 'title' => 'Remove from outline', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('book_remove_form', 1), - 'access callback' => '_book_outline_remove_access', - 'access arguments' => array(1), - 'file' => 'book.pages.inc', + 'route' => 'book_remove', ); return $items; @@ -225,18 +221,6 @@ function _book_outline_access(Node $node) { } /** - * Access callback: Determines if the user can remove nodes from the outline. - * - * @param Drupal\node\Node $node - * The node to remove from the outline. - * - * @see book_menu() - */ -function _book_outline_remove_access(Node $node) { - return _book_node_is_removable($node) && _book_outline_access($node); -} - -/** * Determines if a node can be removed from the book. * * A node can be removed from a book if it is actually in a book and it either diff --git a/core/modules/book/book.pages.inc b/core/modules/book/book.pages.inc index a971aa6..b9afa17 100644 --- a/core/modules/book/book.pages.inc +++ b/core/modules/book/book.pages.inc @@ -204,42 +204,3 @@ function book_outline_form_submit($form, &$form_state) { drupal_set_message(t('There was an error adding the post to the book.'), 'error'); } } - -/** - * Form constructor to confirm removal of a node from a book. - * - * @param Drupal\node\Node $node - * The node to delete. - * - * @see book_remove_form_submit() - * @see book_menu() - * @ingroup forms - */ -function book_remove_form($form, &$form_state, Node $node) { - $form['#node'] = $node; - $title = array('%title' => $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->nid, $description, t('Remove')); -} - -/** - * Form submission handler for book_remove_form(). - */ -function book_remove_form_submit($form, &$form_state) { - $node = $form['#node']; - if (_book_node_is_removable($node)) { - menu_link_delete($node->book['mlid']); - db_delete('book') - ->condition('nid', $node->nid) - ->execute(); - drupal_set_message(t('The post has been removed from the book.')); - } - $form_state['redirect'] = 'node/' . $node->nid; -} diff --git a/core/modules/book/book.routing.yml b/core/modules/book/book.routing.yml new file mode 100644 index 0000000..22325db --- /dev/null +++ b/core/modules/book/book.routing.yml @@ -0,0 +1,6 @@ +book_remove: + pattern: 'node/{node}/outline/remove' + defaults: + _form: '\Drupal\book\Form\BookRemoveForm' + requirements: + _book_outline_remove_access: 'TRUE' diff --git a/core/modules/book/lib/Drupal/book/Access/BookRemoveAccessCheck.php b/core/modules/book/lib/Drupal/book/Access/BookRemoveAccessCheck.php new file mode 100644 index 0000000..4bcb1c2 --- /dev/null +++ b/core/modules/book/lib/Drupal/book/Access/BookRemoveAccessCheck.php @@ -0,0 +1,34 @@ +getRequirements()); + } + + /** + * Implements AccessCheckInterface::access(). + */ + public function access(Route $route, Request $request) { + $node = $request->attributes->get('node'); + return _book_node_is_removable($node) && _book_outline_access($node); + } +} diff --git a/core/modules/book/lib/Drupal/book/BookBundle.php b/core/modules/book/lib/Drupal/book/BookBundle.php new file mode 100644 index 0000000..24be545 --- /dev/null +++ b/core/modules/book/lib/Drupal/book/BookBundle.php @@ -0,0 +1,25 @@ +register('access_check.book.remove', 'Drupal\book\Access\BookRemoveAccessCheck') + ->addTag('access_check'); + } +} diff --git a/core/modules/book/lib/Drupal/book/Form/BookRemoveForm.php b/core/modules/book/lib/Drupal/book/Form/BookRemoveForm.php new file mode 100644 index 0000000..0d75ac6 --- /dev/null +++ b/core/modules/book/lib/Drupal/book/Form/BookRemoveForm.php @@ -0,0 +1,90 @@ +get('database')); + } + + /** + * Constructs a BookRemoveForm object. + * + * @param \Drupal\Core\Database\Connection $database + * Database connection. + */ + public function __construct(Connection $database) { + $this->database = $database; + } + + /** + * Implements \Drupal\Core\Form\FormInterface::getFormID(). + */ + public function getFormID() { + return 'book_remove_form'; + } + + /** + * Implements \Drupal\Core\Form\FormInterface::buildForm(). + * + * Form constructor to confirm removal of a node from a book. + * + * @param Drupal\node\Node $node + * The node to delete. + * + * @see book_menu() + * @see \Drupal\book\Form\BookRemoveForm::submitForm() + */ + public function buildForm(array $form, array &$form_state, Node $node = NULL) { + $form['#node'] = $node; + $title = array('%title' => $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->nid, $description, t('Remove')); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::validateForm(). + */ + public function validateForm(array &$form, array &$form_state) {} + + + /** + * Implements \Drupal\Core\Form\FormInterface::submitForm(). + * + * @see book_menu() + * @see \Drupal\book\Form\BookRemoveForm::buildForm() + */ + public function submitForm(array &$form, array &$form_state) { + $node = $form['#node']; + if (_book_node_is_removable($node)) { + menu_link_delete($node->book['mlid']); + db_delete('book') + ->condition('nid', $node->nid) + ->execute(); + drupal_set_message(t('The post has been removed from the book.')); + } + $form_state['redirect'] = 'node/' . $node->nid; + } + +}