You are here

public function HttpClientManagerConfigForm::submitForm in HTTP Client Manager 8.2

Same name and namespace in other branches
  1. 8 src/Form/HttpClientManagerConfigForm.php \Drupal\http_client_manager\Form\HttpClientManagerConfigForm::submitForm()

Form submission 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 ConfigFormBase::submitForm

File

src/Form/HttpClientManagerConfigForm.php, line 161

Class

HttpClientManagerConfigForm
Class HttpClientManagerConfigForm.

Namespace

Drupal\http_client_manager\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  parent::submitForm($form, $form_state);
  $overrides = $form_state
    ->getValue('overrides');
  foreach ($overrides as $id => $override) {
    foreach ([
      'config',
      'commands',
    ] as $setting) {
      if (!empty($setting)) {
        try {
          $overrides[$id][$setting] = Yaml::decode($overrides[$id][$setting]);
        } catch (InvalidDataTypeException $e) {
          $message = $this
            ->t('There was an error while parsing your YAML data: @message', [
            '@message' => $e
              ->getMessage(),
          ]);
          $this
            ->messenger()
            ->addError($message);
          continue;
        }
      }
    }
    $overrides[$id] = array_filter($overrides[$id]);
  }
  $overrides = array_filter($overrides);
  $this
    ->config('http_client_manager.settings')
    ->set('enable_overriding_service_definitions', $form_state
    ->getValue('enable_overriding_service_definitions'))
    ->set('overrides', $overrides)
    ->save();
}