You are here

function styleswitcher_default_style_key in Style Switcher 8.2

Same name and namespace in other branches
  1. 6.2 styleswitcher.module \styleswitcher_default_style_key()
  2. 7.2 styleswitcher.module \styleswitcher_default_style_key()
  3. 3.0.x styleswitcher.module \styleswitcher_default_style_key()

Finds the default style and returns its key.

Parameters

string $theme: Name of the theme to find the default style for.

Return value

string The key of the default style.

3 calls to styleswitcher_default_style_key()
DefaultController::activeStylePath in src/Controller/DefaultController.php
Finds the style active for current user and returns its path.
Styleswitcher::build in src/Plugin/Block/Styleswitcher.php
Builds and returns the renderable array for this block plugin.
StyleswitcherConfigTheme::buildForm in src/Form/StyleswitcherConfigTheme.php
Form constructor.

File

./styleswitcher.module, line 405
Module's hooks implementations and helper functions.

Code

function styleswitcher_default_style_key($theme) {
  $default_key =& drupal_static(__FUNCTION__, []);

  // Search the default style explicitly set by admin.
  if (!isset($default_key[$theme])) {
    $styles = styleswitcher_style_load_multiple($theme, [
      'is_default' => TRUE,
    ]);
    $default_key[$theme] = key($styles);
  }

  // Plan B. If default style is not set in styles configuration form by admin
  // then find out initial default style defined by theme.
  if (!isset($default_key[$theme])) {
    styleswitcher_theme_styles($theme);
    $default_key[$theme] = styleswitcher_theme_default_style_key($theme);
  }

  // Fallback to the blank style.
  if (!isset($default_key[$theme])) {
    $styles = styleswitcher_style_load_multiple($theme, [
      'path' => NULL,
    ]);
    $default_key[$theme] = key($styles);
  }
  return $default_key[$theme];
}