You are here

abstract class EntityConfirmFormBase in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/EntityConfirmFormBase.php \Drupal\Core\Entity\EntityConfirmFormBase
  2. 9 core/lib/Drupal/Core/Entity/EntityConfirmFormBase.php \Drupal\Core\Entity\EntityConfirmFormBase

Provides a generic base class for an entity-based confirmation form.

Hierarchy

Expanded class hierarchy of EntityConfirmFormBase

Related topics

6 files declare their use of EntityConfirmFormBase
BreakLockForm.php in core/modules/views_ui/src/Form/BreakLockForm.php
FilterDisableForm.php in core/modules/filter/src/Form/FilterDisableForm.php
ImageStyleFlushForm.php in core/modules/image/src/Form/ImageStyleFlushForm.php
VocabularyResetForm.php in core/modules/taxonomy/src/Form/VocabularyResetForm.php
WorkflowDeleteForm.php in core/modules/workflows/src/Form/WorkflowDeleteForm.php

... See full list

File

core/lib/Drupal/Core/Entity/EntityConfirmFormBase.php, line 14

Namespace

Drupal\Core\Entity
View source
abstract class EntityConfirmFormBase extends EntityForm implements ConfirmFormInterface {

  /**
   * {@inheritdoc}
   */
  public function getBaseFormId() {
    return $this->entity
      ->getEntityTypeId() . '_confirm_form';
  }

  /**
   * {@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 = parent::buildForm($form, $form_state);
    $form['#title'] = $this
      ->getQuestion();
    $form['#attributes']['class'][] = 'confirmation';
    $form['description'] = [
      '#markup' => $this
        ->getDescription(),
    ];
    $form[$this
      ->getFormName()] = [
      '#type' => 'hidden',
      '#value' => 1,
    ];

    // By default, render the form using theme_confirm_form().
    if (!isset($form['#theme'])) {
      $form['#theme'] = 'confirm_form';
    }
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  protected function actions(array $form, FormStateInterface $form_state) {
    return [
      'submit' => [
        '#type' => 'submit',
        '#value' => $this
          ->getConfirmText(),
        '#submit' => [
          [
            $this,
            'submitForm',
          ],
        ],
      ],
      'cancel' => ConfirmFormHelper::buildCancelLink($this, $this
        ->getRequest()),
    ];
  }

  /**
   * {@inheritdoc}
   *
   * The save() method is not used in EntityConfirmFormBase. This overrides the
   * default implementation that saves the entity.
   *
   * Confirmation forms should override submitForm() instead for their logic.
   */
  public function save(array $form, FormStateInterface $form_state) {
  }

  /**
   * {@inheritdoc}
   *
   * The delete() method is not used in EntityConfirmFormBase. This overrides
   * the default implementation that redirects to the delete-form confirmation
   * form.
   *
   * Confirmation forms should override submitForm() instead for their logic.
   */
  public function delete(array $form, FormStateInterface $form_state) {
  }

}

Members