You are here

public function TourForm::validateForm in Tour UI 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/TourForm.php, line 300

Class

TourForm
Form controller for the tour entity edit forms.

Namespace

Drupal\tour_ui\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state, $redirect = TRUE) {

  // TODO: validate the routes
  $routes = $this
    ->routesFromArray($form_state
    ->getValue('routes'));

  // Form cannot be validated if a tip has no #data, so no way to export
  // configuration.
  if (!$form_state
    ->isValueEmpty('tips')) {
    foreach ($form_state
      ->getValue('tips') as $key => $values) {
      if (!isset($form['#data'][$key])) {
        $form_state
          ->setError($form['tips'][$key], $this
          ->t('You cannot save the tour while %tip tip cannot be exported.', [
          '%tip' => $this
            ->getEntity()
            ->getTip($key)
            ->getLabel(),
        ]));
      }
    }
  }
}