You are here

public function AddHTTPHeadersSettings::submitForm in HTTP Response Headers 8

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/AddHTTPHeadersSettings.php, line 154
Contains \Drupal\http_response_headers\Form\AddHTTPHeadersSettings.

Class

AddHTTPHeadersSettings
Configure site information settings for this site.

Namespace

Drupal\http_response_headers\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $config = $this
    ->config('http_response_headers.settings');

  // Security
  $security = [
    'Content-Security-Policy' => $form_state
      ->getValue('Content-Security-Policy'),
    'Strict-Transport-Security' => $form_state
      ->getValue('Strict-Transport-Security'),
    'Public-Key-Pins' => $form_state
      ->getValue('Public-Key-Pins'),
    'Access-Control-Allow-Origin' => $form_state
      ->getValue('Access-Control-Allow-Origin'),
    'X-Xss-Protection' => $form_state
      ->getValue('X-Xss-Protection'),
    'X-Frame-Options' => $form_state
      ->getValue('X-Frame-Options'),
    'X-Content-Type-Options' => $form_state
      ->getValue('X-Content-Type-Options'),
  ];

  // Performance
  $performance = [
    'Cache-Control' => $form_state
      ->getValue('Cache-Control'),
  ];

  // Save settings.
  $config
    ->set('security', $security)
    ->set('performance', $performance)
    ->set('performance_authenticated_only', $form_state
    ->getValue('authenticated_only'))
    ->save();

  // Clear Drupal cache.
  drupal_flush_all_caches();
  parent::submitForm($form, $form_state);
}