-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmwc.module
174 lines (142 loc) · 4.15 KB
/
tmwc.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/**
* @file
* Taxonomy menu with children
*/
/**
* Implements hook_menu().
*/
function tmwc_menu() {
$items['admin/config/tmwc'] = array(
'title' => "Taxonomy menu children",
'description' => "Adjusts the module Taxonomy menu with children.",
'position' => 'right',
'weight' => -5,
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('administer site configuration'),
'file path' => drupal_get_path('module', 'system'),
'file' => 'system.admin.inc',
);
$items['admin/config/tmwc/settings'] = array(
'title' => 'Settings',
'description' => "Configuration of Taxonomy menu with children",
'page callback' => 'drupal_get_form',
'page arguments' => array('tmwc_admin_settings'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
'file' => 'tmwc.admin.inc',
);
return $items;
}
/**
* Implements hook_page_build().
*/
function tmwc_page_build(&$page) {
// Applies the bar only on non-administrative paths.
if (path_is_admin(current_path())) {
return;
}
}
/*
* Implements hook_block_info()
*/
function tmwc_block_info(){
$blocks = array();
// Generate blocks of taxonomies
$load_block = variable_get('tmwc_taxonomies');
if(is_array($load_block) && (!empty($load_block)) ){
foreach ($load_block as $taxonomy) {
$vocabulary = taxonomy_vocabulary_machine_name_load($taxonomy);
$block_name = "tmwc_" . $vocabulary->vid;
$blocks[$block_name] = array(
'info' => t("Taxonomy Menu Children: " . $vocabulary->name),
);
}
}
return $blocks;
}
/*
* Implements hook_block_view()
*/
function tmwc_block_view($block_key){
$block = array();
$categories = array();
// Get taxonomies for generate a block
$load_block = variable_get('tmwc_taxonomies');
if(is_array($load_block) && (!empty($load_block)) ){
foreach ($load_block as $taxonomy) {
$vocabulary = taxonomy_vocabulary_machine_name_load($taxonomy);
$block_name = "tmwc_" . $vocabulary->vid;
array_push($categories, $block_name);
}
}
// Add all taxonomies in foreach for apply template of menu
foreach ($categories as $taxonomy) {
if($block_key == $taxonomy){
$vid = explode("_", $block_key);
$vid = $vid[1];
$block['content'] = array(
'#markup' => _body_tmwc($vid),
);
}
}
// Add js of module
drupal_add_js(drupal_get_path('module', 'tmwc') . '/js/global.js', array(
'type' => 'file',
'scope' => 'footer',
'cache' => TRUE,
));
// Add css of module
drupal_add_css(drupal_get_path('module', 'tmwc') . '/css/global.css', array(
'type' => 'file',
'group' => CSS_THEME,
));
return $block;
}
/*
* Generate URL according with termID
*/
function _generateLinkChildren($term){
global $base_path;
$term_uri = taxonomy_term_uri($term); // get array with path
$term_path = $term_uri['path'];
$contar = explode("/", drupal_get_path_alias($term_path));
for($x=0;$x<count($contar);$x++){
$retorno = $contar[$x];
}
$link = "<a href='" . $base_path . 'ciencia/area/' . $retorno . "' title='".$term->name."'><span>" . $term->name . "</span></a>";
return $link;
}
/*
* Generate link of parents, add #
*/
function _generateLinkParent($term){
$link = "<a href='#'><span>" . $term->name . "</span></a>";
return $link;
}
/*
* Generate body for content of block
*/
function _body_tmwc($vid){
$tree = taxonomy_get_tree($vid);
$return = "<div class='tmwc-menu'>";
$return .= "<ul id='tmwc-menu-".$vid."'>";
$return .= "<li class='active'><a href='#'><span>" . t('Categorias') . "</span></a></li>";
foreach ($tree as $term) {
if($term->parents[0] == 0){
$return .= '<li class="has-sub primary-level-'.$term->tid.'">';
$return .= _generateLinkParent($term);
// Detect children of term
$children = taxonomy_get_children($term->tid);
// Browsing the children
$return .= '<ul class="children">';
foreach ($children as $f) {
$return .= '<li>'. _generateLinkChildren($f) . '</li>';
}
$return .= "</ul>";
$return .= '</li>';
}
}
$return .= "</ul></div>";
return $return;
}