summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2013-12-04 05:59:13 (GMT)
committerwebchick2013-12-04 05:59:13 (GMT)
commit349bdb3c546e6aae5c2dbd34b1f51489a6248604 (patch)
tree069d94ad577f6627c70d788d45ddf56917c5351c
parent88db8c57bce93f5ddd0b5daa678dcaf0eb622a2f (diff)
Issue #1938318 by Les Lim, jibran, tim.plunkett, kim.pepper, disasm | Crell: Convert book_remove_form to a new-style Form object.
-rw-r--r--core/modules/book/book.module29
-rw-r--r--core/modules/book/book.pages.inc56
-rw-r--r--core/modules/book/book.routing.yml2
-rw-r--r--core/modules/book/lib/Drupal/book/BookManager.php12
-rw-r--r--core/modules/book/lib/Drupal/book/Form/BookForm.php26
-rw-r--r--core/modules/book/lib/Drupal/book/Form/BookRemoveForm.php124
-rw-r--r--core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageControllerInterface.php2
7 files changed, 138 insertions, 113 deletions
diff --git a/core/modules/book/book.module b/core/modules/book/book.module
index d075b21..ae48054 100644
--- a/core/modules/book/book.module
+++ b/core/modules/book/book.module
@@ -186,35 +186,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');
-}
-
-/**
- * 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 @@
-<?php
-
-/**
- * @file
- * User page callbacks for the book module.
- */
-
-use Drupal\Core\Entity\EntityInterface;
-use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
-use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
-
-/**
- * Form constructor to confirm removal of a node from a book.
- *
- * @param \Drupal\Core\Entity\EntityInterface $node
- * The node to delete.
- *
- * @see book_remove_form_submit()
- * @see book_menu()
- * @ingroup forms
- *
- * @deprecated Use \Drupal\book\Form\BookForm::remove()
- */
-function book_remove_form($form, &$form_state, EntityInterface $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->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 9d941cc..75e3ae8 100644
--- a/core/modules/book/book.routing.yml
+++ b/core/modules/book/book.routing.yml
@@ -52,7 +52,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 @@ class BookManager {
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 @@
-<?php
-/**
- * @file
- * Contains \Drupal\book\Form\BookForm.
- */
-
-namespace Drupal\book\Form;
-
-use Drupal\Core\Entity\EntityInterface;
-
-/**
- * Temporary form controller for book module.
- */
-class BookForm {
-
- /**
- * Wraps book_remove_form().
- *
- * @todo Remove book_remove_form().
- */
- public function remove(EntityInterface $node) {
- module_load_include('pages.inc', 'book');
- return drupal_get_form('book_remove_form', $node);
- }
-
-}
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..ce84ea0
--- /dev/null
+++ b/core/modules/book/lib/Drupal/book/Form/BookRemoveForm.php
@@ -0,0 +1,124 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\book\Form\BookRemoveForm.
+ */
+
+namespace Drupal\book\Form;
+
+use Drupal\book\BookManager;
+use Drupal\Core\Form\ConfirmFormBase;
+use Drupal\node\NodeInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Temporary form controller for book module.
+ */
+class BookRemoveForm extends ConfirmFormBase {
+
+ /**
+ * The book manager.
+ *
+ * @var \Drupal\book\BookManager
+ */
+ protected $bookManager;
+
+ /**
+ * The node representing the book.
+ *
+ * @var \Drupal\node\NodeInterface
+ */
+ protected $node;
+
+ /**
+ * Constructs a BookRemoveForm object.
+ *
+ * @param \Drupal\book\BookManager $book_manager
+ * The book manager.
+ */
+ public function __construct(BookManager $book_manager) {
+ $this->bookManager = $book_manager;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function create(ContainerInterface $container) {
+ return new static(
+ $container->get('book.manager')
+ );
+ }
+
+ /**
+ * {@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_link_delete($this->node->book['mlid']);
+ $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 @@ use Drupal\Core\Entity\EntityStorageControllerInterface;
/**
* 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