You are here

public function AdminSettingsForm::submitForm in Role Based Theme Switcher 8

Same name and namespace in other branches
  1. 9.1.x src/Form/AdminSettingsForm.php \Drupal\role_based_theme_switcher\Form\AdminSettingsForm::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/AdminSettingsForm.php, line 192

Class

AdminSettingsForm
Configure Role Based settings for this site.

Namespace

Drupal\role_based_theme_switcher\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $rollTheme = $form_state
    ->getValue('role_theme');
  $role_arr = [];
  foreach ($rollTheme as $key => $value) {
    $role_arr[(int) $value['weight']] = [
      'theme' => $value['id'],
      'role' => $key,
    ];
    $roles[] = $key;
  }
  ksort($role_arr);
  foreach ($role_arr as $new_key => $new_value) {
    if (in_array($new_value['role'], $roles)) {
      $roll_array[$new_value['role']] = [
        'id' => $new_value['theme'],
        'weight' => $new_key,
      ];
    }
  }
  $roleThemes = $this
    ->config('role_based_theme_switcher.RoleBasedThemeSwitchConfig');
  $roleThemes
    ->set('roletheme', $roll_array);
  $roleThemes
    ->save();
  $this
    ->messenger()
    ->addMessage($this
    ->t("Role theme configuration saved succefully"));

  // Clearing cache for anonymous users.
  drupal_flush_all_caches();
}