You are here

public function HttpPurgerFormBase::submitFormSuccess in Generic HTTP Purger 8

Form submission handler only called when there are no validation errors.

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 PluginConfigFormBase::submitFormSuccess

File

src/Form/HttpPurgerFormBase.php, line 535

Class

HttpPurgerFormBase
Abstract form base for HTTP based configurable purgers.

Namespace

Drupal\purge_purger_http\Form

Code

public function submitFormSuccess(array &$form, FormStateInterface $form_state) {
  $settings = HttpPurgerSettings::load($this
    ->getId($form_state));

  // Empty 'body' when 'show_body_form' isn't checked.
  if ($form_state
    ->getValue('show_body_form') === 0) {
    $form_state
      ->setValue('body', '');
  }

  // Rewrite 'headers' so that it contains the exact right format for CMI.
  if (!is_null($submitted_headers = $form_state
    ->getValue('headers'))) {
    $headers = [];
    foreach ($submitted_headers as $header) {
      if (strlen($header['field'] && strlen($header['value']))) {
        $headers[] = $header;
      }
    }
    $form_state
      ->setValue('headers', $headers);
  }

  // Rewrite 'scheme' and 'request_method' to have the right CMI values.
  if (!is_null($scheme = $form_state
    ->getValue('scheme'))) {
    $form_state
      ->setValue('scheme', $this->schemes[$scheme]);
  }
  if (!is_null($method = $form_state
    ->getValue('request_method'))) {
    $form_state
      ->setValue('request_method', $this->requestMethods[$method]);
  }

  // Iterate the config object and overwrite values found in the form state.
  foreach ($this->settingFields as $key) {
    if (!is_null($value = $form_state
      ->getValue($key))) {
      $settings->{$key} = $value;
    }
  }
  $settings
    ->save();
}