You are here

public function DateRecurModularSierraModalForm::validateForm in Recurring Date Field Modular Widgets 2.x

Same name and namespace in other branches
  1. 8 src/Form/DateRecurModularSierraModalForm.php \Drupal\date_recur_modular\Form\DateRecurModularSierraModalForm::validateForm()
  2. 3.x src/Form/DateRecurModularSierraModalForm.php \Drupal\date_recur_modular\Form\DateRecurModularSierraModalForm::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/DateRecurModularSierraModalForm.php, line 277

Class

DateRecurModularSierraModalForm
Generate a form designed for display in modal.

Namespace

Drupal\date_recur_modular\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $endsMode = $form_state
    ->getValue('ends_mode');

  /** @var \Drupal\Core\Datetime\DrupalDateTime|array|null $endsDate */
  $endsDate = $form_state
    ->getValue('ends_date');
  if ('date' === $endsMode && !$endsDate instanceof DrupalDateTime) {

    // Prevent submission, if for example only date provided (missing time).
    $form_state
      ->setError($form['ends']['ends_date'], $this
      ->t('Invalid date.'));
  }
}