DblogClearLogForm.php 1.54 KB
Newer Older
1 2 3 4 5 6
<?php

namespace Drupal\dblog\Form;

use Drupal\Core\Database\Connection;
use Drupal\Core\Form\FormBase;
7
use Drupal\Core\Form\FormStateInterface;
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Provides the form that clears out the log.
 */
class DblogClearLogForm extends FormBase {

  /**
   * The database connection.
   *
   * @var \Drupal\Core\Database\Connection
   */
  protected $connection;

  /**
   * Constructs a new DblogClearLogForm.
   *
   * @param \Drupal\Core\Database\Connection $connection
   *   The database connection.
   */
  public function __construct(Connection $connection) {
    $this->connection = $connection;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('database')
    );
  }

  /**
   * {@inheritdoc}
   */
44
  public function getFormId() {
45 46 47 48 49 50
    return 'dblog_clear_log_form';
  }

  /**
   * {@inheritdoc}
   */
51
  public function buildForm(array $form, FormStateInterface $form_state) {
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
    $form['dblog_clear'] = array(
      '#type' => 'details',
      '#title' => $this->t('Clear log messages'),
      '#description' => $this->t('This will permanently remove the log messages from the database.'),
    );
    $form['dblog_clear']['clear'] = array(
      '#type' => 'submit',
      '#value' => $this->t('Clear log messages'),
    );
    return $form;
  }

  /**
   * {@inheritdoc}
   */
67
  public function submitForm(array &$form, FormStateInterface $form_state) {
68
    $form_state->setRedirect('dblog.confirm');
69 70 71
  }

}