public function TipPluginTextExtended::optionsFormValidate in Tour UI 8
Validates the selector_type tip optionsForm().
Parameters
mixed $element: The form element that has the validate attached.
\Drupal\Core\Form\FormStateInterface $form_state: The state of the form after submission.
array $form: The form array.
File
- src/
Plugin/ tour_ui/ tip/ TipPluginTextExtended.php, line 183
Class
- TipPluginTextExtended
- This plugin override Tour\tip\TipPluginText to add UI methods.
Namespace
Drupal\tour_ui\Plugin\tour_ui\tipCode
public function optionsFormValidate($element, FormStateInterface $form_state, array $form) {
$selector_type = $form_state
->get([
'attributes',
'selector_type',
]);
$form_state
->unsetValue([
'attributes',
'selector_type',
]);
// If selector_type is modal we need to ensure that there is
// no data-id or data-class specified.
if ($selector_type == 'modal') {
$form_state
->unsetValue([
'attributes',
'data-id',
]);
$form_state
->unsetValue([
'attributes',
'data-class',
]);
}
// If data-id was selected and no id provided.
if ($selector_type == 'data-id' && $form_state
->isValueEmpty([
'attributes',
'data-id',
])) {
$form_state
->setError($form['attributes']['data-id'], $this
->t('Please provide a data id.'));
}
// If data-class was selected and no class provided.
if ($selector_type == 'data-class' && $form_state
->isValueEmpty([
'attributes',
'data-class',
])) {
$form_state
->setError($form['attributes']['data-class'], $this
->t('Please provide a data class.'));
}
// Remove the data-class value if data-id is provided.
if ($selector_type == 'data-id') {
$form_state
->unsetValue([
'attributes',
'data-class',
]);
}
// Remove the data-id value is data-class is provided.
if ($selector_type == 'data-class') {
$form_state
->unsetValue([
'attributes',
'data-id',
]);
}
}