public function TourTipForm::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/ TourTipForm.php, line 137
Class
- TourTipForm
- Form controller for the tour tip plugin edit forms.
Namespace
Drupal\tour_ui\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
// Determine if one of our tips already exist.
$storage = $form_state
->getStorage();
$tour = $storage['#tour'];
$tips = $tour
->getTips();
// If there are no initial tips then we don't need to check.
if (empty($tips)) {
return;
}
$tip_ids = array_map(function ($data) {
return $data
->id();
}, $tips);
if (in_array($form_state
->getValue('id'), $tip_ids) && isset($storage['#new'])) {
$form_state
->setError($form['label'], $this
->t('A tip with the same identifier exists.'));
}
}