3 namespace Drupal\dblog\Form;
5 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\Core\Database\Connection;
8 use Drupal\Core\Form\ConfirmFormBase;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
12 * Provides a confirmation form before clearing out the logs.
16 class DblogClearLogConfirmForm extends ConfirmFormBase {
19 * The database connection.
21 * @var \Drupal\Core\Database\Connection
23 protected $connection;
26 * Constructs a new DblogClearLogConfirmForm.
28 * @param \Drupal\Core\Database\Connection $connection
29 * The database connection.
31 public function __construct(Connection $connection) {
32 $this->connection = $connection;
38 public static function create(ContainerInterface $container) {
40 $container->get('database')
47 public function getFormId() {
48 return 'dblog_confirm';
54 public function getQuestion() {
55 return $this->t('Are you sure you want to delete the recent logs?');
61 public function getCancelUrl() {
62 return new Url('dblog.overview');
68 public function submitForm(array &$form, FormStateInterface $form_state) {
69 $_SESSION['dblog_overview_filter'] = [];
70 $this->connection->truncate('watchdog')->execute();
71 drupal_set_message($this->t('Database log cleared.'));
72 $form_state->setRedirectUrl($this->getCancelUrl());