You are here

public function AppApiKeyAddFormBase::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/AppApiKeyAddFormBase.php, line 151

Class

AppApiKeyAddFormBase
Provides app API key add base form.

Namespace

Drupal\apigee_edge\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $expiry = $form_state
    ->getValue('expiry');
  $expiry_date = $form_state
    ->getValue('expiry_date');

  // Validate expiration date.
  if ($expiry === 'date') {
    if ((new \DateTimeImmutable($expiry_date))
      ->diff(new \DateTimeImmutable())->invert !== 1) {
      $form_state
        ->setError($form['expiry_date'], $this
        ->t('The expiration date must be a future date.'));
    }
  }
}