Same filename and directory in other branches
- 8.9.x core/modules/dblog/src/Form/DblogClearLogConfirmForm.php
- 9 core/modules/dblog/src/Form/DblogClearLogConfirmForm.php
Namespace
Drupal\dblog\Form
File
core/modules/dblog/src/Form/DblogClearLogConfirmForm.php
View source
<?php
namespace Drupal\dblog\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\Core\Database\Connection;
use Drupal\Core\Form\ConfirmFormBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class DblogClearLogConfirmForm extends ConfirmFormBase {
protected $connection;
public function __construct(Connection $connection) {
$this->connection = $connection;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('database'));
}
public function getFormId() {
return 'dblog_confirm';
}
public function getQuestion() {
return $this
->t('Are you sure you want to delete the recent logs?');
}
public function getCancelUrl() {
return new Url('dblog.overview');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->getRequest()
->getSession()
->remove('dblog_overview_filter');
$this->connection
->truncate('watchdog')
->execute();
$this
->messenger()
->addStatus($this
->t('Database log cleared.'));
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
}
Classes