Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / lib / Drupal / Core / Entity / EntityConfirmFormBase.php
1 <?php
2
3 namespace Drupal\Core\Entity;
4
5 use Drupal\Core\Form\ConfirmFormHelper;
6 use Drupal\Core\Form\ConfirmFormInterface;
7 use Drupal\Core\Form\FormStateInterface;
8
9 /**
10  * Provides a generic base class for an entity-based confirmation form.
11  *
12  * @ingroup entity_api
13  */
14 abstract class EntityConfirmFormBase extends EntityForm implements ConfirmFormInterface {
15
16   /**
17    * {@inheritdoc}
18    */
19   public function getBaseFormId() {
20     return $this->entity->getEntityTypeId() . '_confirm_form';
21   }
22
23   /**
24    * {@inheritdoc}
25    */
26   public function getDescription() {
27     return $this->t('This action cannot be undone.');
28   }
29
30   /**
31    * {@inheritdoc}
32    */
33   public function getConfirmText() {
34     return $this->t('Confirm');
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   public function getCancelText() {
41     return $this->t('Cancel');
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public function getFormName() {
48     return 'confirm';
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   public function buildForm(array $form, FormStateInterface $form_state) {
55     $form = parent::buildForm($form, $form_state);
56
57     $form['#title'] = $this->getQuestion();
58
59     $form['#attributes']['class'][] = 'confirmation';
60     $form['description'] = ['#markup' => $this->getDescription()];
61     $form[$this->getFormName()] = ['#type' => 'hidden', '#value' => 1];
62
63     // By default, render the form using theme_confirm_form().
64     if (!isset($form['#theme'])) {
65       $form['#theme'] = 'confirm_form';
66     }
67     return $form;
68   }
69
70   /**
71    * {@inheritdoc}
72    */
73   protected function actions(array $form, FormStateInterface $form_state) {
74     return [
75       'submit' => [
76         '#type' => 'submit',
77         '#value' => $this->getConfirmText(),
78         '#submit' => [
79           [$this, 'submitForm'],
80         ],
81       ],
82       'cancel' => ConfirmFormHelper::buildCancelLink($this, $this->getRequest()),
83     ];
84   }
85
86   /**
87    * {@inheritdoc}
88    *
89    * The save() method is not used in EntityConfirmFormBase. This overrides the
90    * default implementation that saves the entity.
91    *
92    * Confirmation forms should override submitForm() instead for their logic.
93    */
94   public function save(array $form, FormStateInterface $form_state) {}
95
96   /**
97    * {@inheritdoc}
98    *
99    * The delete() method is not used in EntityConfirmFormBase. This overrides
100    * the default implementation that redirects to the delete-form confirmation
101    * form.
102    *
103    * Confirmation forms should override submitForm() instead for their logic.
104    */
105   public function delete(array $form, FormStateInterface $form_state) {}
106
107 }