public function WatchdogPruneSettings::buildForm in Watchdog Prune 8
Same name and namespace in other branches
- 8.2 src/Form/WatchdogPruneSettings.php \Drupal\watchdog_prune\Form\WatchdogPruneSettings::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- src/
Form/ WatchdogPruneSettings.php, line 36
Class
- WatchdogPruneSettings
- Class WatchdogPruneSettings.
Namespace
Drupal\watchdog_prune\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('watchdog_prune.settings');
$database = \Drupal::service('database.replica');
$form['mark_top'] = [
'#markup' => "<p>" . $this
->t("This module allows you to delete watchdog entries, on cron run, based on certain criteria (like age or watchdog entry types).In order for this module to work, Drupal's built in setting <strong>Database log messages to keep</strong>\n must be set to <strong>All</strong>. <br><br><strong>You must have a correctly configured cron task for this module to work.</strong>") . "</p>",
];
$form['core_fs'] = [
'#type' => 'fieldset',
'#title' => $this
->t('From Drupal Core'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
];
$form['core_fs']['dblog_row_limit'] = [
'#type' => 'select',
'#title' => $this
->t('[From Drupal Core:] Database log messages to keep'),
'#options' => [
'0' => 'All',
],
'#default_value' => 0,
'#description' => $this
->t('For this module to function, we must keep this Drupal Core setting set to <strong>All</strong>. This setting is provided here simply as a reminder of where this setting is coming from.'),
];
$prune_age_options = WatchdogPruneSettings::pruneAgeOptions();
$form['watchdog_prune_age'] = [
'#type' => 'select',
'#title' => $this
->t('Delete watchdog entries older than:'),
'#options' => $prune_age_options,
'#default_value' => empty($config
->get('watchdog_prune_age')) ? '-18 MONTHS' : $config
->get('watchdog_prune_age'),
'#description' => $this
->t('Watchdog entries older than this time will be deleted on each cron run. This will ignore all watchdog types entered in "Delete watchdog entries by type" settings.'),
];
$watchdog_types = $database
->query('SELECT DISTINCT(type) FROM {watchdog}')
->fetchCol();
if (count($watchdog_types) === 0) {
$watchdog_types = $this
->t('Watchdog is empty');
}
else {
$watchdog_types = implode(', ', $watchdog_types);
}
$phpdate_reference = Link::fromTextAndUrl($this
->t('PHP Date Manual'), Url::fromUri('http://php.net/manual/en/datetime.formats.relative.php', [
'attributes' => [
'target' => '_blank',
],
]))
->toString();
$form['watchdog_prune_age_type'] = [
'#type' => 'textarea',
'#title' => $this
->t('Delete watchdog entries by type'),
'#description' => $this
->t('Configure different prune time for each watchdog type, enter separate values on new line. Currently <em>logged</em> watchdog entry types are (<em>' . $watchdog_types . '</em>). For all available values for age check the ' . $phpdate_reference . '
<br><br>Insert values with format
<br><b><h4>watchdog_entry_type|age</h4></b>
<br>Examples
<br><b>php|-1 MONTH</b>
<br><b>system|-1 MONTH</b>
</br>This will delete all watchdog entries of type php and system which are older than a month on cron run.'),
'#rows' => 10,
'#cols' => 40,
'#default_value' => empty($config
->get('watchdog_prune_age_type')) ? '' : $config
->get('watchdog_prune_age_type'),
];
return parent::buildForm($form, $form_state);
}