ContentEntityConfirmFormBase.php in Drupal 8
File
core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php
View source
<?php
namespace Drupal\Core\Entity;
use Drupal\Core\Form\ConfirmFormHelper;
use Drupal\Core\Form\ConfirmFormInterface;
use Drupal\Core\Form\FormStateInterface;
abstract class ContentEntityConfirmFormBase extends ContentEntityForm implements ConfirmFormInterface {
public function getBaseFormId() {
return $this->entity
->getEntityTypeId() . '_confirm_form';
}
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 = 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,
];
if (!isset($form['#theme'])) {
$form['#theme'] = 'confirm_form';
}
return $form;
}
public function form(array $form, FormStateInterface $form_state) {
return $form;
}
protected function actions(array $form, FormStateInterface $form_state) {
return [
'submit' => [
'#type' => 'submit',
'#value' => $this
->getConfirmText(),
'#submit' => [
[
$this,
'submitForm',
],
],
],
'cancel' => ConfirmFormHelper::buildCancelLink($this, $this
->getRequest()),
];
}
public function save(array $form, FormStateInterface $form_state) {
}
public function delete(array $form, FormStateInterface $form_state) {
}
public function validateForm(array &$form, FormStateInterface $form_state) {
return $this->entity;
}
}