You are here

public function ConfigEditor::validateForm in Devel 8.2

Same name and namespace in other branches
  1. 8.3 src/Form/ConfigEditor.php \Drupal\devel\Form\ConfigEditor::validateForm()
  2. 8 src/Form/ConfigEditor.php \Drupal\devel\Form\ConfigEditor::validateForm()
  3. 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 89

Class

ConfigEditor
Edit config variable form.

Namespace

Drupal\devel\Form

Code

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', array(
      '%error' => $e
        ->getMessage(),
    )));
  }
}