You are here

DevelopmentEnvironmentClearLogForm.php in Development Environment 8

File

src/Form/DevelopmentEnvironmentClearLogForm.php
View source
<?php

namespace Drupal\development_environment\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Database\Connection;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Form to clear the email log.
 */
class DevelopmentEnvironmentClearLogForm extends FormBase {

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

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

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

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'development_environment_clear_log_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $formState) {
    $form['actions'] = [
      '#type' => 'actions',
    ];
    $form['clear_log'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Clear email log'),
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $formState) {
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $formState) {
    $this->database
      ->query('TRUNCATE {development_environment_log}');
    $this
      ->messenger()
      ->addStatus($this
      ->t('The suppressed email log has been cleared'));
  }

}

Classes

Namesort descending Description
DevelopmentEnvironmentClearLogForm Form to clear the email log.