You are here

function styleswitcher_style_load in Style Switcher 3.0.x

Same name and namespace in other branches
  1. 8.2 styleswitcher.module \styleswitcher_style_load()
  2. 6.2 styleswitcher.module \styleswitcher_style_load()
  3. 7.2 styleswitcher.module \styleswitcher_style_load()

Loads a style array by its machine name and a theme name.

Parameters

string $name: Machine name of the style to load.

string $theme: Machine name of the theme to get the style for.

string $type: (optional) Style type: 'theme' or 'custom'. If the type is specified then it will be prefixed with a slash to the $name argument.

Return value

array|null Style array on success or NULL otherwise. Style is an associative array containing:

  • name: Machine name.
  • label: Human-readable label.
  • path: System or external path to the CSS file.
  • weight: Weight of style link in the switch list.
  • status: Indicates whether the style is enabled or not.
  • is_default: Indicates that this style is the default one. This element may not always show the truth. It is recommended to use styleswitcher_default_style_key() to get the default style key.
  • _i: Index number of the style. It is used for sorting of styles with equal weights.
  • theme: Name of the theme the style is loaded for.

See also

styleswitcher_default_style_key()

3 calls to styleswitcher_style_load()
DefaultController::activeStylePath in src/Controller/DefaultController.php
Finds the style active for current user and returns its path.
StyleswitcherStyleConverter::convert in src/ParamConverter/StyleswitcherStyleConverter.php
Converts path variables to their corresponding objects.
StyleswitcherStyleForm::exists in src/Form/StyleswitcherStyleForm.php
Checks whether a submitted machine name value already exists.

File

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

Code

function styleswitcher_style_load($name, $theme, $type = '') {
  if ($type) {
    $name = $type . '/' . $name;

    // The next conversion is only rationale for auto-loader wildcards in paths
    // and there are $type arguments always set in menu items so if this
    // function is called with only one argument this conversion is redundant.
    $name = strtr($name, '-', '_');
  }
  $styles = styleswitcher_style_load_multiple($theme, [
    'name' => $name,
  ]);
  if ($styles) {
    return reset($styles);
  }
}