function SystemStateEdit::validateForm
Same name in other branches
- 8.x-1.x src/Form/SystemStateEdit.php \Drupal\devel\Form\SystemStateEdit::validateForm()
- 4.x src/Form/SystemStateEdit.php \Drupal\devel\Form\SystemStateEdit::validateForm()
Overrides FormBase::validateForm
File
-
src/
Form/ SystemStateEdit.php, line 134
Class
- SystemStateEdit
- Form API form to edit a state.
Namespace
Drupal\devel\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) : void {
$values = $form_state->getValues();
if ($values['transport'] == 'yaml') {
// Try to parse the new provided value.
try {
$parsed_value = Yaml::decode($values['new_value']);
$form_state->setValue('parsed_value', $parsed_value);
} catch (InvalidDataTypeException $e) {
$form_state->setErrorByName('new_value', $this->t('Invalid input: %error', [
'%error' => $e->getMessage(),
]));
}
}
else {
$form_state->setValue('parsed_value', $values['new_value']);
}
}