You are here

public function StyleswitcherConfigTheme::submitForm in Style Switcher 8.2

Same name and namespace in other branches
  1. 3.0.x src/Form/StyleswitcherConfigTheme.php \Drupal\styleswitcher\Form\StyleswitcherConfigTheme::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 FormInterface::submitForm

File

src/Form/StyleswitcherConfigTheme.php, line 137

Class

StyleswitcherConfigTheme
Configure theme-specific styles settings.

Namespace

Drupal\styleswitcher\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $theme = $form_state
    ->getValue('theme_name');
  $values = $form_state
    ->getValue('settings');
  $theme_settings = [];
  foreach (array_keys(styleswitcher_style_load_multiple($theme)) as $name) {
    $theme_settings[$name] = [
      'weight' => $values['weight'][$name],
      'status' => !empty($values['enabled'][$name]),
      'is_default' => $values['default'] == $name,
    ];
  }

  // Get all settings (for all themes).
  $config = $this
    ->configFactory()
    ->getEditable('styleswitcher.styles_settings');
  $settings = $config
    ->get('settings') ?? [];
  $settings[$theme] = $theme_settings;
  $config
    ->set('settings', $settings)
    ->save();
  $this
    ->messenger()
    ->addStatus($this
    ->t('The configuration options have been saved.'));
}