46344eba06543f2debf6ec2c1775d3c0dc3d76e9
[yaffs-website] / web / core / modules / dblog / src / Form / DblogClearLogConfirmForm.php
1 <?php
2
3 namespace Drupal\dblog\Form;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\Core\Url;
7 use Drupal\Core\Database\Connection;
8 use Drupal\Core\Form\ConfirmFormBase;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
10
11 /**
12  * Provides a confirmation form before clearing out the logs.
13  *
14  * @internal
15  */
16 class DblogClearLogConfirmForm extends ConfirmFormBase {
17
18   /**
19    * The database connection.
20    *
21    * @var \Drupal\Core\Database\Connection
22    */
23   protected $connection;
24
25   /**
26    * Constructs a new DblogClearLogConfirmForm.
27    *
28    * @param \Drupal\Core\Database\Connection $connection
29    *   The database connection.
30    */
31   public function __construct(Connection $connection) {
32     $this->connection = $connection;
33   }
34
35   /**
36    * {@inheritdoc}
37    */
38   public static function create(ContainerInterface $container) {
39     return new static(
40       $container->get('database')
41     );
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public function getFormId() {
48     return 'dblog_confirm';
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   public function getQuestion() {
55     return $this->t('Are you sure you want to delete the recent logs?');
56   }
57
58   /**
59    * {@inheritdoc}
60    */
61   public function getCancelUrl() {
62     return new Url('dblog.overview');
63   }
64
65   /**
66    * {@inheritdoc}
67    */
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());
73   }
74
75 }