Newer
Older
<?php
/**
* @file
* Contains \Drupal\Core\Entity\EntityConfirmFormBase.
*/
namespace Drupal\Core\Entity;
use Drupal\Core\Form\ConfirmFormHelper;
use Drupal\Core\Form\ConfirmFormInterface;
Dries Buytaert
committed
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides a generic base class for an entity-based confirmation form.
Angie Byron
committed
*
* @ingroup entity_api
Alex Pott
committed
abstract class EntityConfirmFormBase extends EntityForm implements ConfirmFormInterface {
Alex Pott
committed
/**
* {@inheritdoc}
*/
public function getBaseFormId() {
return $this->entity->getEntityTypeId() . '_confirm_form';
Alex Pott
committed
}
/**
* {@inheritdoc}
*/
public function getDescription() {
Alex Pott
committed
return $this->t('This action cannot be undone.');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
Alex Pott
committed
return $this->t('Confirm');
}
/**
* {@inheritdoc}
*/
public function getCancelText() {
Alex Pott
committed
return $this->t('Cancel');
}
/**
* {@inheritdoc}
*/
public function getFormName() {
return 'confirm';
}
/**
* {@inheritdoc}
*/
Dries Buytaert
committed
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
Angie Byron
committed
$form['#title'] = $this->getQuestion();
$form['#attributes']['class'][] = 'confirmation';
$form['description'] = array('#markup' => $this->getDescription());
$form[$this->getFormName()] = array('#type' => 'hidden', '#value' => 1);
// By default, render the form using theme_confirm_form().
if (!isset($form['#theme'])) {
$form['#theme'] = 'confirm_form';
}
return $form;
}
/**
* {@inheritdoc}
*/
Dries Buytaert
committed
protected function actions(array $form, FormStateInterface $form_state) {
return array(
'submit' => array(
'#type' => 'submit',
'#value' => $this->getConfirmText(),
'#submit' => array(
array($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) {}