You are here

public function SettingsForm::submitForm in Advanced CSS/JS Aggregation 8.2

Same name in this branch
  1. 8.2 src/Form/SettingsForm.php \Drupal\advagg\Form\SettingsForm::submitForm()
  2. 8.2 advagg_ext_minify/src/Form/SettingsForm.php \Drupal\advagg_ext_minify\Form\SettingsForm::submitForm()
  3. 8.2 advagg_mod/src/Form/SettingsForm.php \Drupal\advagg_mod\Form\SettingsForm::submitForm()
  4. 8.2 advagg_css_minify/src/Form/SettingsForm.php \Drupal\advagg_css_minify\Form\SettingsForm::submitForm()
  5. 8.2 advagg_js_minify/src/Form/SettingsForm.php \Drupal\advagg_js_minify\Form\SettingsForm::submitForm()
  6. 8.2 advagg_cdn/src/Form/SettingsForm.php \Drupal\advagg_cdn\Form\SettingsForm::submitForm()
  7. 8.2 advagg_bundler/src/Form/SettingsForm.php \Drupal\advagg_bundler\Form\SettingsForm::submitForm()
Same name and namespace in other branches
  1. 8.4 advagg_css_minify/src/Form/SettingsForm.php \Drupal\advagg_css_minify\Form\SettingsForm::submitForm()
  2. 8.3 advagg_css_minify/src/Form/SettingsForm.php \Drupal\advagg_css_minify\Form\SettingsForm::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

advagg_css_minify/src/Form/SettingsForm.php, line 172

Class

SettingsForm
Configure advagg_css_minify settings for this site.

Namespace

Drupal\advagg_css_minify\Form

Code

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

  // Extract/combine per file settings.
  if ($file_settings = $config
    ->get('file_settings')) {
    $file_settings = array_column($file_settings, NULL, 'path');
  }
  else {
    $file_settings = [];
  }
  foreach ($form_state
    ->getValues() as $key => $value) {

    // Skip if not advagg_css_minify_file_settings.
    if (strpos($key, 'advagg_css_minify_file_settings_') === FALSE) {
      continue;
    }
    $path = str_replace([
      '__',
      '--',
    ], [
      '/',
      '.',
    ], substr($key, 32));
    if ($value == -1) {
      unset($file_settings[$path]);
      continue;
    }
    else {
      $file_settings[$path] = [
        'path' => $path,
        'minifier' => $value,
      ];
    }
  }

  // Clear relevant caches.
  $this->cssCollectionOptimizer
    ->deleteAll();
  Cache::invalidateTags([
    'library_info',
    'advagg_css',
  ]);
  $config = $this
    ->config('advagg_css_minify.settings')
    ->set('minifier', $form_state
    ->getValue('minifier'))
    ->set('file_settings', array_values($file_settings))
    ->save();
  parent::submitForm($form, $form_state);
}