ConfirmFormBase.php in Drupal 8
File
core/lib/Drupal/Core/Form/ConfirmFormBase.php
View source
<?php
namespace Drupal\Core\Form;
abstract class ConfirmFormBase extends FormBase implements ConfirmFormInterface {
public function getDescription() {
return $this
->t('This action cannot be undone.');
}
public function getConfirmText() {
return $this
->t('Confirm');
}
public function getCancelText() {
return $this
->t('Cancel');
}
public function getFormName() {
return 'confirm';
}
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());
if (!isset($form['#theme'])) {
$form['#theme'] = 'confirm_form';
}
return $form;
}
}