View source
<?php
namespace Drupal\webform\Form;
use Drupal\Core\Entity\EntityDeleteFormTrait;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\ConfirmFormHelper;
use Drupal\Core\Form\FormStateInterface;
abstract class WebformConfigEntityDeleteFormBase extends EntityForm implements WebformDeleteFormInterface {
use EntityDeleteFormTrait;
use WebformDialogFormTrait;
protected $confirmCheckbox = TRUE;
public function getBaseFormId() {
return $this->entity
->getEntityTypeId() . '_confirm_form';
}
public function getQuestion() {
if ($this
->isDialog()) {
$t_args = [
'@entity-type' => $this
->getEntity()
->getEntityType()
->getSingularLabel(),
'@label' => $this
->getEntity()
->label(),
];
return $this
->t("Delete '@label' @entity-type?", $t_args);
}
else {
$t_args = [
'@entity-type' => $this
->getEntity()
->getEntityType()
->getSingularLabel(),
'%label' => $this
->getEntity()
->label(),
];
return $this
->t('Delete %label @entity-type?', $t_args);
}
}
public function getWarning() {
$t_args = [
'@entity-type' => $this
->getEntity()
->getEntityType()
->getSingularLabel(),
'%label' => $this
->getEntity()
->label(),
];
return [
'#type' => 'webform_message',
'#message_type' => 'warning',
'#message_message' => $this
->t('Are you sure you want to delete the %label @entity-type?', $t_args) . '<br/>' . '<strong>' . $this
->t('This action cannot be undone.') . '</strong>',
];
}
public function getDescription() {
return [];
}
public function getDetails() {
return [];
}
public function getConfirmInput() {
$t_args = [
'@entity-type' => $this
->getEntity()
->getEntityType()
->getSingularLabel(),
'%label' => $this
->getEntity()
->label(),
];
if ($this->confirmCheckbox) {
return [
'#type' => 'checkbox',
'#title' => $this
->t('Yes, I want to delete the %label @entity-type', $t_args),
'#required' => TRUE,
];
}
else {
return [];
}
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function getCancelText() {
return $this
->t('Cancel');
}
public function getFormName() {
return 'webform_config_entity_delete';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$form['#attributes']['class'][] = 'confirmation';
$form['#theme'] = 'confirm_form';
$form[$this
->getFormName()] = [
'#type' => 'hidden',
'#value' => 1,
];
$form['#title'] = $this
->getQuestion();
$form['warning'] = $this
->getWarning();
$form['description'] = $this
->getDescription();
$details = $this
->getDetails();
$confirm_input = $this
->getConfirmInput();
if ($details) {
$form['details'] = $details;
}
if (!$details && $confirm_input) {
$form['hr'] = [
'#markup' => '<p><hr/></p>',
];
}
if ($confirm_input) {
$form['confirm'] = $confirm_input;
}
return $this
->buildDialogConfirmForm($form, $form_state);
}
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) {
}
}