3 namespace Drupal\book\Form;
5 use Drupal\book\BookManagerInterface;
6 use Drupal\Core\Form\ConfirmFormBase;
7 use Drupal\Core\Form\FormStateInterface;
8 use Drupal\node\NodeInterface;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
12 * Remove form for book module.
16 class BookRemoveForm extends ConfirmFormBase {
21 * @var \Drupal\book\BookManagerInterface
23 protected $bookManager;
26 * The node representing the book.
28 * @var \Drupal\node\NodeInterface
33 * Constructs a BookRemoveForm object.
35 * @param \Drupal\book\BookManagerInterface $book_manager
38 public function __construct(BookManagerInterface $book_manager) {
39 $this->bookManager = $book_manager;
45 public static function create(ContainerInterface $container) {
47 $container->get('book.manager')
54 public function getFormId() {
55 return 'book_remove_form';
61 public function buildForm(array $form, FormStateInterface $form_state, NodeInterface $node = NULL) {
63 return parent::buildForm($form, $form_state);
69 public function getDescription() {
70 $title = ['%title' => $this->node->label()];
71 if ($this->node->book['has_children']) {
72 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);
75 return $this->t('%title may be added to hierarchy again using the Outline tab.', $title);
82 public function getConfirmText() {
83 return $this->t('Remove');
89 public function getQuestion() {
90 return $this->t('Are you sure you want to remove %title from the book hierarchy?', ['%title' => $this->node->label()]);
96 public function getCancelUrl() {
97 return $this->node->urlInfo();
103 public function submitForm(array &$form, FormStateInterface $form_state) {
104 if ($this->bookManager->checkNodeIsRemovable($this->node)) {
105 $this->bookManager->deleteFromBook($this->node->id());
106 drupal_set_message($this->t('The post has been removed from the book.'));
108 $form_state->setRedirectUrl($this->getCancelUrl());