View source
<?php
namespace Drupal\webform\Form;
use Drupal\Core\Form\FormStateInterface;
class WebformResultsClearForm extends WebformSubmissionsDeleteFormBase {
public function getFormId() {
return 'webform_results_clear';
}
public function getQuestion() {
$t_args = [
'%label' => $this
->getLabel(),
];
return $this
->t('Clear all %label submissions?', $t_args);
}
public function buildForm(array $form, FormStateInterface $form_state) {
$submission_total = $this
->getSubmissionTotal();
if ($submission_total) {
return parent::buildForm($form, $form_state);
}
else {
$t_args = [
'%label' => $this
->getLabel(),
];
$form['message'] = [
'#type' => 'webform_message',
'#message_type' => 'error',
'#message_message' => $this
->t('There are no %label submissions.', $t_args),
];
return $form;
}
}
public function getWarning() {
$t_args = [
'%label' => $this
->getLabel(),
];
return [
'#type' => 'webform_message',
'#message_type' => 'warning',
'#message_message' => $this
->t('Are you sure you want to clear all %label submissions?', $t_args) . '<br/>' . '<strong>' . $this
->t('This action cannot be undone.') . '</strong>',
];
}
public function getDescription() {
$submission_total = $this
->getSubmissionTotal();
$t_args = [
'%label' => $this
->getLabel(),
'@total' => $submission_total,
'@submissions' => $this
->formatPlural($submission_total, 'submission', 'submissions'),
];
return [
'title' => [
'#markup' => $this
->t('This action will…'),
],
'list' => [
'#theme' => 'item_list',
'#items' => [
$this
->t('Remove @total %label @submissions', $t_args),
[
'#markup' => '<em>' . $this
->t('Take a few minutes to complete') . '</em>',
],
],
],
];
}
public function getConfirmInput() {
$t_args = [
'%label' => $this
->getLabel(),
];
return [
'#type' => 'checkbox',
'#title' => $this
->t('Yes, I want to clear all %label submissions', $t_args),
'#required' => TRUE,
];
}
public function getCancelUrl() {
return $this->requestHandler
->getUrl($this->webform, $this->sourceEntity, 'webform.results_submissions');
}
public function getMessage() {
$t_args = [
'%label' => $this
->getLabel(),
];
$this
->t('Webform %label submissions cleared.', $t_args);
}
}