forked from isubit/luggage_indicator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathluggage_indicator.module
82 lines (70 loc) · 2.17 KB
/
luggage_indicator.module
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
<?php
/**
* @file
* Drupal needs this blank file.
*/
/**
* Implements hook_update_projects_alter().
*/
function luggage_indicator_update_projects_alter(&$projects) {
// Hide a site-specific module from the list.
unset($projects['luggage_indicator']);
}
function luggage_indicator_node_view_alter(&$build) {
if(arg(0) == 'search') {
$build['field_content_type'] = array(
'#markup' => _get_identifier_element(node_type_get_name($build['#node']), 'ct-search', true),
'#weight' => 0
);
_add_stylesheet();
} else if(arg(0) == 'node') {
$build['field_content_type_indicator'] = array(
'#title' => 'Content Type Indicator',
'#label_display' => 'none',
0 => array(
'#markup' => _get_identifier_element(node_type_get_name($build['#node']), 'ct-node', true)
)
);
_add_stylesheet();
}
}
function luggage_indicator_preprocess_node(&$variables) {
if($variables) {
}
}
// function luggage_indicator_block_view_alter(&$data, $block) {
// if($block->delta == 'GiIy4zr9Gu0ZSa0bumw1Y9qIIpIDf1wu' && $data != NULL) {
// foreach($data['content']['bundle']['#items'] as &$item) {
// $name = strtolower(_get_string_between($item['data'], '>', ' ('));
// if($name == 'basic page') {
// $name = 'page';
// }
// $item['data'] = _get_identifier_element($name, 'block', false) . $item['data'];
// }
// _add_stylesheet();
// }
// }
function _add_stylesheet() {
drupal_add_css(drupal_get_path('module', 'luggage_indicator') . '/css/luggage_indicator.css');
}
function _get_identifier_element($name, $type, $title) {
$str = '<div class="content-type-indicator ct-' . $name . ' '. $type;
if($title) {
$str = $str . '" title="' . ucfirst($name) . ' content type';
}
$str = $str . '">';
if($type == 'block') {
$str = $str . ucfirst(substr($name, 0, 2)) . '</div>';
} else {
$str = $str . ucfirst($name) . '</div>';
}
return $str;
}
function _get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}