class BookRemoveForm
Same name and namespace in other branches
- 10 core/modules/book/src/Form/BookRemoveForm.php \Drupal\book\Form\BookRemoveForm
- 8.9.x core/modules/book/src/Form/BookRemoveForm.php \Drupal\book\Form\BookRemoveForm
Remove form for book module.
@internal
Hierarchy
- class \Drupal\Core\Form\FormBase implements \Drupal\Core\Form\FormInterface, \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Logger\LoggerChannelTrait, \Drupal\Core\Messenger\MessengerTrait, \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
- class \Drupal\Core\Form\ConfirmFormBase implements \Drupal\Core\Form\ConfirmFormInterface extends \Drupal\Core\Form\FormBase
- class \Drupal\book\Form\BookRemoveForm extends \Drupal\Core\Form\ConfirmFormBase
- class \Drupal\Core\Form\ConfirmFormBase implements \Drupal\Core\Form\ConfirmFormInterface extends \Drupal\Core\Form\FormBase
Expanded class hierarchy of BookRemoveForm
1 string reference to 'BookRemoveForm'
- book.routing.yml in core/
modules/ book/ book.routing.yml - core/modules/book/book.routing.yml
File
-
core/
modules/ book/ src/ Form/ BookRemoveForm.php, line 16
Namespace
Drupal\book\FormView source
class BookRemoveForm extends ConfirmFormBase {
/**
* The book manager.
*
* @var \Drupal\book\BookManagerInterface
*/
protected $bookManager;
/**
* The node representing the book.
*
* @var \Drupal\node\NodeInterface
*/
protected $node;
/**
* Constructs a BookRemoveForm object.
*
* @param \Drupal\book\BookManagerInterface $book_manager
* The book manager.
*/
public function __construct(BookManagerInterface $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, FormStateInterface $form_state, NodeInterface $node = NULL) {
$this->node = $node;
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function getDescription() {
$title = [
'%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?', [
'%title' => $this->node
->label(),
]);
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return $this->node
->toUrl();
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($this->bookManager
->checkNodeIsRemovable($this->node)) {
$this->bookManager
->deleteFromBook($this->node
->id());
$this->messenger()
->addStatus($this->t('The post has been removed from the book.'));
}
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.