function styleswitcher_block_view in Style Switcher 6.2
Same name and namespace in other branches
- 7.2 styleswitcher.module \styleswitcher_block_view()
- 7 styleswitcher.module \styleswitcher_block_view()
Returns a renderable view of a block.
Parameters
string|int $delta: Which block to render.
Return value
array An array of block subject and content.
See also
1 call to styleswitcher_block_view()
- styleswitcher_block in ./
styleswitcher.module - Implements hook_block().
File
- ./
styleswitcher.module, line 61 - Module's hooks implementations and helper functions.
Code
function styleswitcher_block_view($delta) {
global $theme;
switch ($delta) {
// List of styles a user can switch between.
case 0:
$styles = styleswitcher_style_load_multiple($theme, array(
'status' => TRUE,
));
// Do not display block if there is only one style (no alternatives).
if (count($styles) > 1) {
uasort($styles, 'styleswitcher_sort');
$links = array();
$destination = drupal_get_destination();
foreach ($styles as $name => $style) {
$name_hyphenated = strtr($name, '_', '-');
$name_parts = explode('/', $name_hyphenated);
$class = 'style-switcher ' . $name_parts[0] . '-style style-' . $name_parts[1];
$links[] = l($style['label'], 'styleswitcher/switch/' . $theme . '/' . $name_hyphenated, array(
'attributes' => array(
'class' => $class,
'data-rel' => $name,
'rel' => 'nofollow',
),
'query' => $destination,
));
// Make paths absolute for JS.
if (isset($style['path'])) {
$styles[$name]['path'] = _styleswitcher_file_create_url($style['path']);
}
else {
$styles[$name]['path'] = url('styleswitcher/css/' . $theme, array(
'absolute' => TRUE,
));
}
}
$path_to_module = drupal_get_path('module', 'styleswitcher');
$js_settings = array(
'styleSwitcher' => array(
'styles' => $styles,
'default' => styleswitcher_default_style_key($theme),
'enableOverlay' => variable_get('styleswitcher_enable_overlay', 1),
'cookieExpire' => STYLESWITCHER_COOKIE_EXPIRE,
'theme' => $theme,
),
);
drupal_add_css($path_to_module . '/styleswitcher.overlay.css');
drupal_add_js($path_to_module . '/styleswitcher.js');
drupal_add_js($js_settings, 'setting');
$block['subject'] = t('Style Switcher');
$block['content'] = theme('item_list', $links);
return $block;
}
break;
}
}