You are here

public function WatchdogPruneSettings::validateForm in Watchdog Prune 8

Same name and namespace in other branches
  1. 8.2 src/Form/WatchdogPruneSettings.php \Drupal\watchdog_prune\Form\WatchdogPruneSettings::validateForm()

Form validation handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormBase::validateForm

File

src/Form/WatchdogPruneSettings.php, line 103

Class

WatchdogPruneSettings
Class WatchdogPruneSettings.

Namespace

Drupal\watchdog_prune\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $prune_type = $form_state
    ->getValue('watchdog_prune_age_type');
  if (!empty($prune_type)) {
    $prune_type = explode("\n", $prune_type);
    if (is_array($prune_type)) {
      $current_date = strtotime('today');
      foreach ($prune_type as $key => $value) {
        $watchdog_prune_settings = explode("|", $value);
        $user_entered_date = strtotime(trim($watchdog_prune_settings[1]));
        if ($current_date < $user_entered_date) {
          $form_state
            ->setErrorByName('watchdog_prune_age_type', $this
            ->t('Incorrect value for <b>' . implode("|", $watchdog_prune_settings) . '</b> Watchdog Prune age must be older than todays date'));
        }
      }
    }
  }
}