You are here

function styleswitcher_style_load_multiple in Style Switcher 8.2

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

Returns a list of styles.

Parameters

string $theme: Name of the theme to get styles for.

array $filter: Style properties to filter by. Each key is a property name, and value is a corresponding filter value.

Return value

array Array of styles - all or just filtered by conditions from the $filter argument. Keys are machine names and each element is a corresponding style array, which structure is the same as returned from styleswitcher_style_load().

See also

styleswitcher_style_load()

6 calls to styleswitcher_style_load_multiple()
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.
StyleswitcherConfigTheme::submitForm in src/Form/StyleswitcherConfigTheme.php
Form submission handler.
StyleswitcherConfigTheme::weightDelta in src/Form/StyleswitcherConfigTheme.php
Calculates #delta for style's weight element.
styleswitcher_default_style_key in ./styleswitcher.module
Finds the default style and returns its key.

... See full list

File

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

Code

function styleswitcher_style_load_multiple($theme, array $filter = []) {
  $styles =& drupal_static(__FUNCTION__, []);
  if (!isset($styles[$theme])) {
    $theme_styles = styleswitcher_custom_styles() + styleswitcher_theme_styles($theme);
    $settings = styleswitcher_styles_settings($theme);
    foreach (array_keys($theme_styles) as $i => $key) {
      if (isset($settings[$key])) {
        $theme_styles[$key] += $settings[$key];
      }

      // Default settings.
      $theme_styles[$key] += [
        'is_default' => FALSE,
        'status' => TRUE,
        'weight' => 0,
        '_i' => $i,
        'theme' => $theme,
      ];
    }
    $styles[$theme] = $theme_styles;
  }
  if (empty($filter)) {
    return $styles[$theme];
  }
  $return = [];
  foreach ($styles[$theme] as $key => $style) {

    // Check the requested conditions.
    foreach ($filter as $property => $value) {
      if ($style[$property] != $value) {
        continue 2;
      }
    }
    $return[$key] = $style;
  }
  return $return;
}