You are here

public function AppAnalyticsFormBase::validateForm in Apigee Edge 8

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/AppAnalyticsFormBase.php, line 281

Class

AppAnalyticsFormBase
App analytics form builder for developer- and team apps.

Namespace

Drupal\apigee_edge\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $since = $form_state
    ->getValue('since');
  $until = $form_state
    ->getValue('until');
  if ($since instanceof DrupalDateTime && $until instanceof DrupalDateTime) {
    if ($since
      ->getTimestamp() !== $until
      ->getTimestamp()) {
      if ($since
        ->diff($until)->invert === 1) {
        $form_state
          ->setError($form['controls']['until'], $this
          ->t('The end date cannot be before the start date.'));
      }
    }
  }
}