You are here

public function MessageDigestIntervalForm::validateForm in Message Digest 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/MessageDigestIntervalForm.php, line 59

Class

MessageDigestIntervalForm
Config form for message digest intervals.

Namespace

Drupal\message_digest\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);

  // Verify interval is valid.
  try {

    // This will throw an exception if the submitted interval is invalid.
    new \DateTime($form_state
      ->getValue('interval'));
  } catch (\Exception $e) {
    $form_state
      ->setErrorByName('interval', $this
      ->t('The interval %interval is invalid. See <a href=":url">the relative time formats documentation</a> for more information.', [
      ':url' => 'http://php.net/manual/en/datetime.formats.relative.php',
      '%interval' => $form_state
        ->getValue('interval'),
    ]));
  }
}