class ConfirmFormBase

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Form/ConfirmFormBase.php \Drupal\Core\Form\ConfirmFormBase
  2. 9 core/lib/Drupal/Core/Form/ConfirmFormBase.php \Drupal\Core\Form\ConfirmFormBase
  3. 10 core/lib/Drupal/Core/Form/ConfirmFormBase.php \Drupal\Core\Form\ConfirmFormBase

Provides an generic base class for a confirmation form.

Hierarchy

Expanded class hierarchy of ConfirmFormBase

29 files declare their use of ConfirmFormBase
BanDelete.php in core/modules/ban/src/Form/BanDelete.php
BookRemoveForm.php in core/modules/book/src/Form/BookRemoveForm.php
ConfigSingleImportForm.php in core/modules/config/src/Form/ConfigSingleImportForm.php
ConfigTranslationDeleteForm.php in core/modules/config_translation/src/Form/ConfigTranslationDeleteForm.php
ConfirmFormTestForm.php in core/modules/system/tests/modules/form_test/src/ConfirmFormTestForm.php

... See full list

File

core/lib/Drupal/Core/Form/ConfirmFormBase.php, line 8

Namespace

Drupal\Core\Form
View source
abstract class ConfirmFormBase extends FormBase implements ConfirmFormInterface {
  
  /**
   * {@inheritdoc}
   */
  public function getDescription() {
    return $this->t('This action cannot be undone.');
  }
  
  /**
   * {@inheritdoc}
   */
  public function getConfirmText() {
    return $this->t('Confirm');
  }
  
  /**
   * {@inheritdoc}
   */
  public function getCancelText() {
    return $this->t('Cancel');
  }
  
  /**
   * {@inheritdoc}
   */
  public function getFormName() {
    return 'confirm';
  }
  
  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['#title'] = $this->getQuestion();
    $form['#attributes']['class'][] = 'confirmation';
    $form['description'] = [
      '#markup' => $this->getDescription(),
    ];
    $form[$this->getFormName()] = [
      '#type' => 'hidden',
      '#value' => 1,
    ];
    $form['actions'] = [
      '#type' => 'actions',
    ];
    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->getConfirmText(),
      '#button_type' => 'primary',
    ];
    $form['actions']['cancel'] = ConfirmFormHelper::buildCancelLink($this, $this->getRequest());
    // By default, render the form using theme_confirm_form().
    if (!isset($form['#theme'])) {
      $form['#theme'] = 'confirm_form';
    }
    return $form;
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.