Provide Theme::setAdmin() and Theme::isAdmin()

Created on 22 September 2023, about 1 year ago

Problem/Motivation

The helper module kindly offers an easy way to set the default theme for a site, but not a kind and helpful way to set the admin theme for a site. It would be great to offer the equivalent of setDefault() and isDefault() for the admin theme.

Proposed resolution

Something like so:

/**
   * Sets the admin theme.
   *
   * @param string $theme_name
   *   Theme name.
   *
   * @return bool
   *   TRUE if the admin theme was updated, or FALSE if the requested theme
   *   was already the admin.
   */
  public function setAdmin(string $theme_name): bool {
    if (!$this->themeHandler->themeExists($theme_name)) {
      $this->themeInstaller->install([$theme_name]);
    }
    if (!$this->isAdmin($theme_name)) {
      $this->configFactory->getEditable('system.theme')->set('admin', $theme_name)->save();
      $this->themeManager->resetActiveTheme();
      return TRUE;
    }
    return FALSE;
  }

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States owenbush Denver, CO

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024