3 namespace Drupal\Core\Form;
6 * Provides an generic base class for a confirmation form.
8 abstract class ConfirmFormBase extends FormBase implements ConfirmFormInterface {
13 public function getDescription() {
14 return $this->t('This action cannot be undone.');
20 public function getConfirmText() {
21 return $this->t('Confirm');
27 public function getCancelText() {
28 return $this->t('Cancel');
34 public function getFormName() {
41 public function buildForm(array $form, FormStateInterface $form_state) {
42 $form['#title'] = $this->getQuestion();
44 $form['#attributes']['class'][] = 'confirmation';
45 $form['description'] = ['#markup' => $this->getDescription()];
46 $form[$this->getFormName()] = ['#type' => 'hidden', '#value' => 1];
48 $form['actions'] = ['#type' => 'actions'];
49 $form['actions']['submit'] = [
51 '#value' => $this->getConfirmText(),
52 '#button_type' => 'primary',
55 $form['actions']['cancel'] = ConfirmFormHelper::buildCancelLink($this, $this->getRequest());
57 // By default, render the form using theme_confirm_form().
58 if (!isset($form['#theme'])) {
59 $form['#theme'] = 'confirm_form';