Skip to content
Snippets Groups Projects
Commit 349bdb3c authored by Angie Byron's avatar Angie Byron
Browse files

Issue #1938318 by Les Lim, jibran, tim.plunkett, kim.pepper, disasm | Crell:...

Issue #1938318 by Les Lim, jibran, tim.plunkett, kim.pepper, disasm | Crell: Convert book_remove_form to a new-style Form object.
parent 88db8c57
No related branches found
No related tags found
No related merge requests found
......@@ -185,35 +185,6 @@ function book_menu() {
return $items;
}
/**
* 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().
*/
......
<?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(),
),
);
}
......@@ -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'
......
......@@ -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();
}
}
<?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);
}
}
<?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(),
),
);
}
}
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment