forked from artesis/ding_toggle_format
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathding_toggle_format.module
More file actions
75 lines (63 loc) · 2 KB
/
ding_toggle_format.module
File metadata and controls
75 lines (63 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* @file
* Ding - toggle short/long format
*/
/**
* Implements hook_block_info().
*/
function ding_toggle_format_block_info() {
return array(
'toggle' => array(
'info' => t('Ding format toggle'),
'cache' => DRUPAL_CACHE_PER_PAGE,
),
);
}
/**
* Implements hook_block_view().
*/
function ding_toggle_format_block_view($delta = '') {
drupal_add_js(drupal_get_path('module', 'ding_toggle_format') . '/js/ding_toggle_format.js');
drupal_add_js(drupal_get_path('module', 'ding_toggle_format') . '/js/jquery.cookie.min.js');
drupal_add_css(drupal_get_path('module', 'ding_toggle_format') . '/css/ding_toggle_format.css');
return array(
'subject' => t('Ding toggle format'),
'content' => ding_toggle_format_render_link(),
);
}
/**
* Return rendered image link to toggle format, and label.
*/
function ding_toggle_format_render_link() {
// get view_type from url
$view_type = arg(1);
// construct the image's path (.gif stored in a module subdir)
$image_path = drupal_get_path('module', 'ding_toggle_format') . '/images/blank.gif';
// make some text for the image's alt & title tags (SEO, accessibility)
$image_alt = t('Toggle format');
$image_title = t('Toggle format link');
$format_link = '<span class="ding-toggle-format-label">' . t('Display format: ') . '</span>';
// render image html using theme_image (returns NULL if file doesn't exist)
if ($view_type != 'collection') {
$format_image = theme('image', array(
'path' => $image_path,
'alt' => $image_alt,
'title' => $image_title,
'attributes' => array(
'id' => 'ding-toggle-format-image',
),
));
// if the image rendered ok, render link using above variables
$image_link = l($format_image, '#', array(
'html' => TRUE,
'attributes' => array(
'title' => $image_title,
'id' => 'ding-toggle-format',
'class' => 'ding-toggle-format-short',
),
));
$format_link .= $image_link;
}
return $format_link;
}