public function SystemStateEdit::validateForm in Devel 8
Same name and namespace in other branches
- 8.3 src/Form/SystemStateEdit.php \Drupal\devel\Form\SystemStateEdit::validateForm()
- 8.2 src/Form/SystemStateEdit.php \Drupal\devel\Form\SystemStateEdit::validateForm()
- 4.x src/Form/SystemStateEdit.php \Drupal\devel\Form\SystemStateEdit::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/ SystemStateEdit.php, line 129
Class
- SystemStateEdit
- Form API form to edit a state.
Namespace
Drupal\devel\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$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', array(
'%error' => $e
->getMessage(),
)));
}
}
else {
$form_state
->setValue('parsed_value', $values['new_value']);
}
}