function SystemStateEdit::validateForm

Same name in other branches
  1. 5.x src/Form/SystemStateEdit.php \Drupal\devel\Form\SystemStateEdit::validateForm()

Overrides FormBase::validateForm

File

src/Form/SystemStateEdit.php, line 131

Class

SystemStateEdit
Form API form to edit a state.

Namespace

Drupal\devel\Form

Code

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', [
                '%error' => $e->getMessage(),
            ]));
        }
    }
    else {
        $form_state->setValue('parsed_value', $values['new_value']);
    }
}