ConfirmFormBase.php 1.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
<?php

/**
 * @file
 * Contains \Drupal\Core\Form\ConfirmFormBase.
 */

namespace Drupal\Core\Form;

/**
 * Provides an generic base class for a confirmation form.
 */
13
abstract class ConfirmFormBase extends FormBase implements ConfirmFormInterface {
14 15

  /**
16
   * {@inheritdoc}
17
   */
18
  public function getDescription() {
19 20 21 22
    return t('This action cannot be undone.');
  }

  /**
23
   * {@inheritdoc}
24
   */
25
  public function getConfirmText() {
26 27 28 29
    return t('Confirm');
  }

  /**
30
   * {@inheritdoc}
31
   */
32
  public function getCancelText() {
33 34 35 36
    return t('Cancel');
  }

  /**
37
   * {@inheritdoc}
38
   */
39
  public function getFormName() {
40 41 42 43
    return 'confirm';
  }

  /**
44
   * {@inheritdoc}
45
   */
46
  public function buildForm(array $form, array &$form_state) {
47
    $form['#title'] = $this->getQuestion();
48 49 50 51 52 53 54 55 56 57

    $form['#attributes']['class'][] = 'confirmation';
    $form['description'] = array('#markup' => $this->getDescription());
    $form[$this->getFormName()] = array('#type' => 'hidden', '#value' => 1);

    $form['actions'] = array('#type' => 'actions');
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => $this->getConfirmText(),
    );
58 59 60

    $form['actions']['cancel'] = ConfirmFormHelper::buildCancelLink($this, $this->getRequest());

61 62 63 64 65 66 67 68
    // By default, render the form using theme_confirm_form().
    if (!isset($form['#theme'])) {
      $form['#theme'] = 'confirm_form';
    }
    return $form;
  }

}