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;
class DevelopmentEnvironmentClearLogForm extends FormBase {
protected $database;
public function __construct(Connection $database) {
$this->database = $database;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('database'));
}
public function getFormId() {
return 'development_environment_clear_log_form';
}
public function buildForm(array $form, FormStateInterface $formState) {
$form['actions'] = [
'#type' => 'actions',
];
$form['clear_log'] = [
'#type' => 'submit',
'#value' => $this
->t('Clear email log'),
];
return $form;
}
public function validateForm(array &$form, FormStateInterface $formState) {
}
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'));
}
}