View source
<?php
namespace Drupal\webform\Form;
use Drupal\Core\Entity\Form\DeleteMultipleForm;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
abstract class WebformDeleteMultipleFormBase extends DeleteMultipleForm {
public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL) {
$request = $this
->getRequest();
$destination = $request->query
->get('destination');
if ($destination) {
$update_destination = preg_replace('/^' . preg_quote(base_path(), '/') . '/', '/', $destination);
$request->query
->set('destination', $update_destination);
$form = parent::buildForm($form, $form_state, $entity_type_id);
$request->query
->set('destination', $destination);
}
else {
$form = parent::buildForm($form, $form_state, $entity_type_id);
}
if ($form instanceof RedirectResponse) {
return $form;
}
$form['message'] = $this
->getWarning();
$form['entities'] += [
'#prefix' => $this
->formatPlural(count($this->selection), 'The below @item will be deleted.', 'The below @items will be deleted.', [
'@item' => $this->entityType
->getSingularLabel(),
'@items' => $this->entityType
->getPluralLabel(),
]),
'#suffix' => '<p><hr/></p>',
];
$form['description'] = $this
->getDescription();
$form['hr'] = [
'#markup' => '<p><hr/></p>',
];
$form['confirm_input'] = $this
->getConfirmInput();
return $form;
}
public function getQuestion() {
return $this
->formatPlural(count($this->selection), 'Delete this @item?', 'Delete these @items?', [
'@item' => $this->entityType
->getSingularLabel(),
'@items' => $this->entityType
->getPluralLabel(),
]);
}
public function getDescription() {
return [];
}
public function getWarning() {
$message = $this
->formatPlural(count($this->selection), 'Are you sure you want to delete this @item?', 'Are you sure you want to delete these @items?', [
'@item' => $this->entityType
->getSingularLabel(),
'@items' => $this->entityType
->getPluralLabel(),
]);
return [
'#type' => 'webform_message',
'#message_type' => 'warning',
'#message_message' => $message,
'#weight' => -10,
];
}
public function getConfirmInput() {
return [
'#type' => 'checkbox',
'#title' => $this
->formatPlural(count($this->selection), 'Yes, I want to delete this @item?', 'Yes, I want to delete these @items?', [
'@item' => $this->entityType
->getSingularLabel(),
'@items' => $this->entityType
->getPluralLabel(),
]),
'#required' => TRUE,
];
}
}