You are here

function styleswitcher_pre_render_styles in Style Switcher 7.2

Render API callback: Adds HTML id for Styleswitcher style link.

Searches for the styleswitcher link HTML element to add an id to it.

This function is assigned as a #pre_render callback in styleswitcher_element_info_alter().

1 string reference to 'styleswitcher_pre_render_styles'
styleswitcher_element_info_alter in ./styleswitcher.module
Implements hook_element_info_alter().

File

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

Code

function styleswitcher_pre_render_styles(array $elements) {

  // There must be at least one element in array because the dynamic CSS is
  // always added to the page's styles. Walk in reverse order because the needed
  // <link> is closer to end of array.
  $element = end($elements);
  do {
    if (!empty($element['#attributes']['media']) && $element['#attributes']['media'] == 'styleswitcher') {

      // Set 'media' back to its default value.
      $element['#attributes']['media'] = 'all';

      // Add an ID.
      $element['#attributes']['id'] = 'styleswitcher-css';
      $elements[key($elements)] = $element;
      break;
    }
  } while ($element = prev($elements));
  return $elements;
}