QueueEmptyForm.php in Purge 8.3
File
modules/purge_ui/src/Form/QueueEmptyForm.php
View source
<?php
namespace Drupal\purge_ui\Form;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\CloseModalDialogCommand;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\purge\Plugin\Purge\Queue\QueueServiceInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class QueueEmptyForm extends ConfirmFormBase {
use CloseDialogTrait;
protected $purgeQueue;
public final function __construct(QueueServiceInterface $purge_queue) {
$this->purgeQueue = $purge_queue;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('purge.queue'));
}
protected function getEditableConfigNames() {
return [];
}
public function getFormId() {
return 'purge_ui.queue_empty_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
$form['actions']['submit'] = [
'#type' => 'submit',
'#button_type' => 'primary',
'#value' => $this
->getConfirmText(),
'#ajax' => [
'callback' => '::emptyQueue',
],
];
$form['actions']['cancel'] = [
'#type' => 'submit',
'#value' => $this
->t('No'),
'#weight' => -10,
'#ajax' => [
'callback' => '::closeDialog',
],
];
return $form;
}
public function getConfirmText() {
return $this
->t('Yes, throw everything away!');
}
public function getQuestion() {
return $this
->t('Are you sure you want to empty the queue?');
}
public function getCancelUrl() {
return NULL;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
}
public function emptyQueue(array &$form, FormStateInterface $form_state) {
$this->purgeQueue
->emptyQueue();
$response = new AjaxResponse();
$response
->addCommand(new CloseModalDialogCommand());
return $response;
}
}