public function ConditionalFieldEditForm::validateForm in Conditional Fields 8
Same name and namespace in other branches
- 4.x src/Form/ConditionalFieldEditForm.php \Drupal\conditional_fields\Form\ConditionalFieldEditForm::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/ ConditionalFieldEditForm.php, line 291
Class
- ConditionalFieldEditForm
- Class ConditionalFieldEditForm.
Namespace
Drupal\conditional_fields\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$allowed_values_set = [
ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_AND,
ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_OR,
ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_XOR,
ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_NOT,
];
if ($form_state
->getValue('condition') == 'value') {
if (in_array($form_state
->getValue('values_set'), $allowed_values_set) && mb_strlen(trim($form_state
->getValue('values')) === 0)) {
$form_state
->setErrorByName('values', $this
->t('Field %name is required.', [
'%name' => $this
->t('Set of values'),
]));
}
elseif ($form_state
->getValue('values_set') == ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX && mb_strlen(trim($form_state
->getValue('regex'))) == 0) {
$form_state
->setErrorByName('regex', $this
->t('Field %name is required.', [
'%name' => $this
->t('Regular expression'),
]));
}
}
parent::validateForm($form, $form_state);
}