View source
<?php
namespace Drupal\webform\Form;
use Drupal\Core\Entity\ContentEntityDeleteForm;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\webform\WebformRequestInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class WebformSubmissionDeleteForm extends ContentEntityDeleteForm implements WebformDeleteFormInterface {
use WebformDialogFormTrait;
protected $webform;
protected $webformSubmission;
protected $sourceEntity;
protected $requestHandler;
public function __construct(EntityRepositoryInterface $entity_repository, WebformRequestInterface $request_handler) {
parent::__construct($entity_repository);
$this->requestHandler = $request_handler;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity.repository'), $container
->get('webform.request'));
}
public function buildForm(array $form, FormStateInterface $form_state) {
list($this->webformSubmission, $this->sourceEntity) = $this->requestHandler
->getWebformSubmissionEntities();
$this->webform = $this->webformSubmission
->getWebform();
$form['warning'] = $this
->getWarning();
$form = parent::buildForm($form, $form_state);
$form['description'] = $this
->getDescription();
return $this
->buildDialogConfirmForm($form, $form_state);
}
protected function actions(array $form, FormStateInterface $form_state) {
$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);
$actions = parent::actions($form, $form_state);
$request->query
->set('destination', $destination);
return $actions;
}
else {
return parent::actions($form, $form_state);
}
}
public function getQuestion() {
$t_args = [
'%label' => $this
->getEntity()
->label(),
];
return $this
->t('Delete %label?', $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 [
'title' => [
'#markup' => $this
->t('This action will…'),
],
'list' => [
'#theme' => 'item_list',
'#items' => [
$this
->t('Remove records from the database'),
$this
->t('Delete any uploaded files'),
$this
->t('Cancel all pending actions'),
],
],
];
}
public function getDetails() {
return [];
}
public function getConfirmInput() {
return [];
}
protected function getDeletionMessage() {
return $this
->t('%label has been deleted.', [
'%label' => $this->webformSubmission
->label(),
]);
}
public function getCancelUrl() {
if ($this->webform
->access('submission_view_own') || $this->webform
->access('submission_view_any')) {
$base_route_name = strpos(\Drupal::routeMatch()
->getRouteName(), 'webform.user.submission.delete') !== FALSE ? 'webform.user.submissions' : 'webform.results_submissions';
return $this->requestHandler
->getUrl($this->webform, $this->sourceEntity, $base_route_name);
}
elseif ($this->sourceEntity && $this->sourceEntity
->hasLinkTemplate('canonical') && $this->sourceEntity
->access('view')) {
return $this->sourceEntity
->toUrl();
}
elseif ($this->webform
->access('view')) {
return $this->webform
->toUrl();
}
else {
return Url::fromRoute('<front>');
}
}
protected function getRedirectUrl() {
return $this
->getCancelUrl();
}
protected function logDeletionMessage() {
}
}