You are here

public function SystemStateEdit::validateForm in Devel 8

Same name and namespace in other branches
  1. 8.3 src/Form/SystemStateEdit.php \Drupal\devel\Form\SystemStateEdit::validateForm()
  2. 8.2 src/Form/SystemStateEdit.php \Drupal\devel\Form\SystemStateEdit::validateForm()
  3. 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\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', array(
        '%error' => $e
          ->getMessage(),
      )));
    }
  }
  else {
    $form_state
      ->setValue('parsed_value', $values['new_value']);
  }
}