-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlytical_blocks.module
More file actions
91 lines (83 loc) · 2.44 KB
/
lytical_blocks.module
File metadata and controls
91 lines (83 loc) · 2.44 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
function lytical_social_media_services() {
return array(
// Field name => fontawesome-class
'Drupal' => 'drupal',
'Twitter' => 'twitter-square',
'LinkedIn' => 'linkedin-square',
'Github' => 'github-alt',
'RSS' => 'rss-square',
);
}
/**
* Implementation of hook_block_info().
*/
function lytical_blocks_block_info() {
$blocks['copyright'] = array(
'info' => t('Copyright block with dynamic year'),
);
$blocks['social_media_links'] = array(
'info' => t('Social media links'),
);
return $blocks;
}
/**
* Implements hook_block_configure().
*/
function lytical_blocks_block_configure($delta = '') {
if ($delta == 'social_media_links') {
$form = array();
$services = lytical_social_media_services();
foreach ($services as $service => $class) {
$lower = strtolower($service);
$form['lytical_blocks_' . $lower] = array(
'#type' => 'textfield',
'#title' => $service . ' link',
'#default_value' => variable_get('lytical_blocks_' . $lower, '')
);
}
return $form;
}
}
/**
* Implements hook_block_save().
*/
function lytical_blocks_block_save($delta = '', $edit = array()) {
if ($delta == 'social_media_links') {
$services = lytical_social_media_services();
foreach ($services as $service => $class) {
$lower = strtolower($service);
if ($edit['lytical_blocks_' . $lower] != '') {
variable_set('lytical_blocks_' . $lower, $edit['lytical_blocks_' . $lower]);
}
}
}
}
/**
* Implementation fo hook_block_view().
*/
function lytical_blocks_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'copyright':
$block['content'] = '<p>' . t('© !year. All Rights Reserved.', array('!year' => date('Y'))) . '</p>';
break;
case 'social_media_links':
$items = array();
$services = lytical_social_media_services();
foreach ($services as $service => $class) {
$lower = strtolower($service);
if (variable_get('lytical_blocks_' . $lower)) {
$items[] = l('<i class="fa fa-' . $class . '"></i>', variable_get('lytical_blocks_' . $lower), array('html' => TRUE));
}
}
$variables = array(
'items' => $items,
'type' => 'ul'
);
$block['content']['#markup'] = theme('item_list', $variables);
$block['content']['#attached'] = array('libraries_load' => array(array('fontawesome')));
break;
}
return $block;
}