YamlFormSubmissionsPurgeForm.php in YAML Form 8
File
src/Form/YamlFormSubmissionsPurgeForm.php
View source
<?php
namespace Drupal\yamlform\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class YamlFormSubmissionsPurgeForm extends YamlFormSubmissionsDeleteFormBase {
public function getFormId() {
return 'yamlform_submissions_purge';
}
public function getQuestion() {
return $this
->t('Are you sure you want to delete all submissions?');
}
public function getConfirmText() {
return $this
->t('Purge');
}
public function getCancelUrl() {
return new Url('entity.yamlform_submission.collection');
}
public function getFinishedMessage() {
return $this
->t('Form submissions purged.');
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$submission_total = \Drupal::entityQuery('yamlform_submission')
->count()
->execute();
$form_total = \Drupal::entityQuery('yamlform')
->count()
->execute();
$t_args = [
'@submission_total' => $submission_total,
'@submissions' => $this
->formatPlural($submission_total, $this
->t('submission'), $this
->t('submissions')),
'@form_total' => $form_total,
'@forms' => $this
->formatPlural($form_total, $this
->t('form'), $this
->t('forms')),
];
$form['confirm'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Are you sure you want to delete @submission_total @submissions in @form_total @forms?', $t_args),
'#required' => TRUE,
'#weight' => -10,
];
return $form;
}
}