public function ConfigEditor::validateForm in Devel 8.3
Same name and namespace in other branches
- 8 src/Form/ConfigEditor.php \Drupal\devel\Form\ConfigEditor::validateForm()
- 8.2 src/Form/ConfigEditor.php \Drupal\devel\Form\ConfigEditor::validateForm()
- 4.x src/Form/ConfigEditor.php \Drupal\devel\Form\ConfigEditor::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/ ConfigEditor.php, line 97
Class
- ConfigEditor
- Edit config variable form.
Namespace
Drupal\devel\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$value = $form_state
->getValue('new');
// Try to parse the new provided value.
try {
$parsed_value = Yaml::decode($value);
// Config::setData needs array for the new configuration and
// a simple string is valid YAML for any reason.
if (is_array($parsed_value)) {
$form_state
->setValue('parsed_value', $parsed_value);
}
else {
$form_state
->setErrorByName('new', $this
->t('Invalid input'));
}
} catch (InvalidDataTypeException $e) {
$form_state
->setErrorByName('new', $this
->t('Invalid input: %error', [
'%error' => $e
->getMessage(),
]));
}
}