function ConfigEditor::submitForm

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

Overrides FormInterface::submitForm

File

src/Form/ConfigEditor.php, line 149

Class

ConfigEditor
Edit config variable form.

Namespace

Drupal\devel\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) : void {
    $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
            ->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
            ->error('Error saving configuration variable %variable : %error.', [
            '%variable' => $values['name'],
            '%error' => $e->getMessage(),
        ]);
    }
}