You are here

public function AmpSettingsForm::submitForm in Accelerated Mobile Pages (AMP) 8

Same name and namespace in other branches
  1. 8.3 src/Form/AmpSettingsForm.php \Drupal\amp\Form\AmpSettingsForm::submitForm()
  2. 8.2 src/Form/AmpSettingsForm.php \Drupal\amp\Form\AmpSettingsForm::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/AmpSettingsForm.php, line 300

Class

AmpSettingsForm
Defines the configuration export form.

Namespace

Drupal\amp\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // AMP theme settings.
  $amptheme = $form_state
    ->getValue('amptheme');
  $amptheme_config = $this
    ->config('amp.theme');
  $amptheme_config
    ->setData([
    'amptheme' => $amptheme,
  ]);
  $amptheme_config
    ->save();

  // Other module settings.
  $amp_config = $this
    ->config('amp.settings');
  $amp_config
    ->set('google_analytics_id', $form_state
    ->getValue('google_analytics_id'))
    ->save();
  $amp_config
    ->set('google_adsense_id', $form_state
    ->getValue('google_adsense_id'))
    ->save();
  $amp_config
    ->set('google_doubleclick_id', $form_state
    ->getValue('google_doubleclick_id'))
    ->save();
  $amp_config
    ->set('amp_pixel', $form_state
    ->getValue('amp_pixel'))
    ->save();
  $amp_config
    ->set('amp_pixel_domain_name', $form_state
    ->getValue('amp_pixel_domain_name'))
    ->save();
  $amp_config
    ->set('amp_pixel_query_string', $form_state
    ->getValue('amp_pixel_query_string'))
    ->save();
  $amp_config
    ->set('amp_pixel_random_number', $form_state
    ->getValue('amp_pixel_random_number'))
    ->save();
  $amp_config
    ->set('amp_library_process_full_html', $form_state
    ->getValue('amp_library_process_full_html'))
    ->save();
  $amp_config
    ->set('amp_library_process_full_html_warnings', $form_state
    ->getValue('amp_library_process_full_html_warnings'))
    ->save();
  $amp_config
    ->set('amp_library_process_statistics', $form_state
    ->getValue('amp_library_process_statistics'))
    ->save();
  if ($form_state
    ->getValue('amp_library_warnings_display') !== $amp_config
    ->get('amp_library_warnings_display')) {
    $amp_config
      ->set('amp_library_warnings_display', $form_state
      ->getValue('amp_library_warnings_display'))
      ->save();
    $this->tagInvalidate
      ->invalidateTags([
      'amp-warnings',
    ]);
  }
  parent::submitForm($form, $form_state);
}