function ConfigEditor::submitForm

Same name in other branches
  1. 8.x-1.x src/Form/ConfigEditor.php \Drupal\devel\Form\ConfigEditor::submitForm()
  2. 5.x src/Form/ConfigEditor.php \Drupal\devel\Form\ConfigEditor::submitForm()

Overrides FormInterface::submitForm

File

src/Form/ConfigEditor.php, line 120

Class

ConfigEditor
Edit config variable form.

Namespace

Drupal\devel\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
    $values = $form_state->getValues();
    try {
        $this->configFactory()
            ->getEditable($values['name'])
            ->setData($values['parsed_value'])
            ->save();
        $this->messenger()
            ->addMessage($this->t('Configuration variable %variable was successfully saved.', [
            '%variable' => $values['name'],
        ]));
        $this->logger('devel')
            ->info('Configuration variable %variable was successfully saved.', [
            '%variable' => $values['name'],
        ]);
        $form_state->setRedirectUrl(Url::fromRoute('devel.configs_list'));
    } catch (\Exception $e) {
        $this->messenger()
            ->addError($e->getMessage());
        $this->logger('devel')
            ->error('Error saving configuration variable %variable : %error.', [
            '%variable' => $values['name'],
            '%error' => $e->getMessage(),
        ]);
    }
}