3 namespace Drupal\Core\Entity;
5 use Drupal\Core\Form\ConfirmFormHelper;
6 use Drupal\Core\Form\ConfirmFormInterface;
7 use Drupal\Core\Form\FormStateInterface;
10 * Provides a generic base class for an entity-based confirmation form.
14 abstract class EntityConfirmFormBase extends EntityForm implements ConfirmFormInterface {
19 public function getBaseFormId() {
20 return $this->entity->getEntityTypeId() . '_confirm_form';
26 public function getDescription() {
27 return $this->t('This action cannot be undone.');
33 public function getConfirmText() {
34 return $this->t('Confirm');
40 public function getCancelText() {
41 return $this->t('Cancel');
47 public function getFormName() {
54 public function buildForm(array $form, FormStateInterface $form_state) {
55 $form = parent::buildForm($form, $form_state);
57 $form['#title'] = $this->getQuestion();
59 $form['#attributes']['class'][] = 'confirmation';
60 $form['description'] = ['#markup' => $this->getDescription()];
61 $form[$this->getFormName()] = ['#type' => 'hidden', '#value' => 1];
63 // By default, render the form using theme_confirm_form().
64 if (!isset($form['#theme'])) {
65 $form['#theme'] = 'confirm_form';
73 protected function actions(array $form, FormStateInterface $form_state) {
77 '#value' => $this->getConfirmText(),
79 [$this, 'submitForm'],
82 'cancel' => ConfirmFormHelper::buildCancelLink($this, $this->getRequest()),
89 * The save() method is not used in EntityConfirmFormBase. This overrides the
90 * default implementation that saves the entity.
92 * Confirmation forms should override submitForm() instead for their logic.
94 public function save(array $form, FormStateInterface $form_state) {}
99 * The delete() method is not used in EntityConfirmFormBase. This overrides
100 * the default implementation that redirects to the delete-form confirmation
103 * Confirmation forms should override submitForm() instead for their logic.
105 public function delete(array $form, FormStateInterface $form_state) {}