Version 1
[yaffs-website] / web / core / lib / Drupal / Core / Form / ConfirmFormBase.php
1 <?php
2
3 namespace Drupal\Core\Form;
4
5 /**
6  * Provides an generic base class for a confirmation form.
7  */
8 abstract class ConfirmFormBase extends FormBase implements ConfirmFormInterface {
9
10   /**
11    * {@inheritdoc}
12    */
13   public function getDescription() {
14     return $this->t('This action cannot be undone.');
15   }
16
17   /**
18    * {@inheritdoc}
19    */
20   public function getConfirmText() {
21     return $this->t('Confirm');
22   }
23
24   /**
25    * {@inheritdoc}
26    */
27   public function getCancelText() {
28     return $this->t('Cancel');
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public function getFormName() {
35     return 'confirm';
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public function buildForm(array $form, FormStateInterface $form_state) {
42     $form['#title'] = $this->getQuestion();
43
44     $form['#attributes']['class'][] = 'confirmation';
45     $form['description'] = ['#markup' => $this->getDescription()];
46     $form[$this->getFormName()] = ['#type' => 'hidden', '#value' => 1];
47
48     $form['actions'] = ['#type' => 'actions'];
49     $form['actions']['submit'] = [
50       '#type' => 'submit',
51       '#value' => $this->getConfirmText(),
52       '#button_type' => 'primary',
53     ];
54
55     $form['actions']['cancel'] = ConfirmFormHelper::buildCancelLink($this, $this->getRequest());
56
57     // By default, render the form using theme_confirm_form().
58     if (!isset($form['#theme'])) {
59       $form['#theme'] = 'confirm_form';
60     }
61     return $form;
62   }
63
64 }