Révision 98a362c2
Ajouté par Assos Assos il y a plus de 6 ans
drupal7/sites/all/modules/adminimal_admin_menu/adminimal_admin_menu.admin.inc | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
/** |
|
4 |
* @file |
|
5 |
* Administation settings for Adminimal Admin Menu. |
|
6 |
*/ |
|
7 |
|
|
8 |
/** |
|
9 |
* Settings page form. |
|
10 |
*/ |
|
11 |
function adminimal_admin_menu_settings($form, &$form_state) { |
|
12 |
|
|
13 |
// Create the shortcut category. |
|
14 |
$form['shortcut'] = array( |
|
15 |
'#type' => 'fieldset', |
|
16 |
'#title' => t('Shortcut options'), |
|
17 |
); |
|
18 |
|
|
19 |
if (module_exists('shortcut')) { |
|
20 |
// Create the select list. |
|
21 |
$form['shortcut']['adminimal_admin_menu_render'] = array( |
|
22 |
'#type' => 'radios', |
|
23 |
'#title' => t('Rendering method'), |
|
24 |
'#default_value' => variable_get('adminimal_admin_menu_render', 'collapsed'), |
|
25 |
'#options' => array( |
|
26 |
'hidden' => t('Hidden'), |
|
27 |
'inline' => t('Inline'), |
|
28 |
'collapsed' => t('Collapsed'), |
|
29 |
'newline' => t('Newline'), |
|
30 |
'dropdown' => t('Dropdown'), |
|
31 |
'exclusive' => t('Exclusive'), |
|
32 |
), |
|
33 |
'#required' => TRUE, |
|
34 |
); |
|
35 |
|
|
36 |
$descriptions = &$form['shortcut']['adminimal_admin_menu_render']; |
|
37 |
$descriptions['hidden']['#description'] = t('Shortcuts will not be rendered inside the admin menu.'); |
|
38 |
$descriptions['inline']['#description'] = t('Shortcuts will be rendered on the same line with the root menu links.'); |
|
39 |
$descriptions['collapsed']['#description'] = t('Shortcuts will be collapsed like a normal menu.'); |
|
40 |
$descriptions['newline']['#description'] = t('<b>(Default)</b>') . ' ' . t('Shortcuts will be rendered on a new line, below the root menu links.'); |
|
41 |
$descriptions['dropdown']['#description'] = t('Shortcuts will be rendered inside a dropdown using the select html tag.'); |
|
42 |
$descriptions['exclusive']['#description'] = t('Only the shortcuts will be rendered; the normal menu will be hidden.'); |
|
43 |
} |
|
44 |
else { |
|
45 |
$form['shortcut']['#description'] = t('Module Shortcut is supported, but not required by Adminimal Admin Menu.'); |
|
46 |
} |
|
47 |
|
|
48 |
// Create the advanced settings category. |
|
49 |
$form['advanced_settings'] = array( |
|
50 |
'#type' => 'fieldset', |
|
51 |
'#title' => t('Advanced settings'), |
|
52 |
'#description' => t('Do not change any of the advanced setting unless you know what you are doing!'), |
|
53 |
'#collapsible' => TRUE, |
|
54 |
'#collapsed' => TRUE, |
|
55 |
); |
|
56 |
|
|
57 |
$form['advanced_settings']['adminimal_admin_menu_slicknav'] = array( |
|
58 |
'#type' => 'checkbox', |
|
59 |
'#default_value' => variable_get('adminimal_admin_menu_slicknav', TRUE), |
|
60 |
'#title' => t('Enable Responsive Menu.'), |
|
61 |
'#description' => t('Enable this option if you want to have responsive menu and mobile device support. While disabling this option could save you few kilobytes (around 3KB), it will completely disable the responsive menu functionality.'), |
|
62 |
); |
|
63 |
|
|
64 |
$form['advanced_settings']['adminimal_admin_menu_jquery'] = array( |
|
65 |
'#type' => 'checkbox', |
|
66 |
'#default_value' => variable_get('adminimal_admin_menu_jquery', TRUE), |
|
67 |
'#title' => t('Load the required jQuery 1.7 library automagically.'), |
|
68 |
'#description' => t('This will load the newer jQuery version 1.7 using the no-conflict method so it won\'t interfere with any existing jQuery or other JavaScript libraries. The only reason to un-check this if you are already using a newer version of jQuery site-wide and its globally accessible by the "$" variable. Un-cheking this option could save you 33KB, but it may also break your JavaScript if not used correctly.'), |
|
69 |
'#states' => array( |
|
70 |
// Hide the settings when the cancel notify checkbox is disabled. |
|
71 |
'visible' => array( |
|
72 |
':input[name="adminimal_admin_menu_slicknav"]' => array('checked' => TRUE), |
|
73 |
), |
|
74 |
), |
|
75 |
); |
|
76 |
|
|
77 |
$form['advanced_settings']['adminimal_admin_menu_viewport'] = array( |
|
78 |
'#type' => 'checkbox', |
|
79 |
'#default_value' => variable_get('adminimal_admin_menu_viewport', TRUE), |
|
80 |
'#title' => t('Set the metatag viewport <em>\'width=device-width, initial-scale=1\'</em> for devices.'), |
|
81 |
'#description' => t('This is needed for the responsive menu, if no other theme or module sets the viewport.'), |
|
82 |
'#states' => array( |
|
83 |
// Hide the settings when the cancel notify checkbox is disabled. |
|
84 |
'visible' => array( |
|
85 |
':input[name="adminimal_admin_menu_slicknav"]' => array('checked' => TRUE), |
|
86 |
), |
|
87 |
), |
|
88 |
); |
|
89 |
|
|
90 |
$form = system_settings_form($form); |
|
91 |
|
|
92 |
$form['#submit'][] = 'adminimal_admin_menu_settings_submit'; |
|
93 |
|
|
94 |
return $form; |
|
95 |
} |
|
96 |
|
|
97 |
/** |
|
98 |
* Submit callback for adminimal_admin_menu_settings(); |
|
99 |
*/ |
|
100 |
function adminimal_admin_menu_settings_submit($form, &$form_state) { |
|
101 |
// Clear the admin menu cache. |
|
102 |
admin_menu_flush_caches(); |
|
103 |
} |
drupal7/sites/all/modules/adminimal_admin_menu/adminimal_admin_menu.info | ||
---|---|---|
6 | 6 |
configure = admin/config/administration/adminimal_menu |
7 | 7 |
|
8 | 8 |
; Information added by Drupal.org packaging script on 2018-02-28 |
9 |
version = "7.x-1.8"
|
|
9 |
version = "7.x-1.9"
|
|
10 | 10 |
core = "7.x" |
11 | 11 |
project = "adminimal_admin_menu" |
12 |
datestamp = "1519846986"
|
|
12 |
datestamp = "1519862286"
|
|
13 | 13 |
|
drupal7/sites/all/modules/adminimal_admin_menu/adminimal_admin_menu.module | ||
---|---|---|
10 | 10 |
*/ |
11 | 11 |
function adminimal_admin_menu_menu() { |
12 | 12 |
$items = array(); |
13 |
|
|
13 | 14 |
$items['admin/config/administration/adminimal_menu'] = array( |
14 | 15 |
'title' => 'Adminimal menu', |
15 | 16 |
'description' => 'Adjust adminimal menu settings.', |
16 | 17 |
'page callback' => 'drupal_get_form', |
17 | 18 |
'page arguments' => array('adminimal_admin_menu_settings'), |
18 | 19 |
'access arguments' => array('administer site configuration'), |
19 |
'file' => 'adminimal_menu_settings.inc',
|
|
20 |
'file' => 'adminimal_admin_menu.admin.inc',
|
|
20 | 21 |
); |
21 | 22 |
|
22 | 23 |
return $items; |
23 | 24 |
} |
24 | 25 |
|
26 |
/** |
|
27 |
* Implements hook_module_implements_alter(). |
|
28 |
*/ |
|
29 |
function adminimal_admin_menu_module_implements_alter(&$implementations, $hook) { |
|
30 |
// Put Adminimal Admin Menu's implementation of hook_admin_menu_output_alter() |
|
31 |
// to the end of the list of implementors, assuring that it will be executed |
|
32 |
// at the very end. Other modules may manipulate the menu items in the |
|
33 |
// administration menu (i.e. the excellent Administration Menu Source) and we |
|
34 |
// need to make sure those changes are preserved and respected by the output |
|
35 |
// of Adminimal Admin Menu. |
|
36 |
if ($hook == 'admin_menu_output_alter') { |
|
37 |
$group = $implementations['adminimal_admin_menu']; |
|
38 |
unset($implementations['adminimal_admin_menu']); |
|
39 |
$implementations['adminimal_admin_menu'] = $group; |
|
40 |
} |
|
41 |
} |
|
42 |
|
|
25 | 43 |
/** |
26 | 44 |
* Implements hook_page_build(). |
27 | 45 |
*/ |
... | ... | |
73 | 91 |
$attached = &$page['page_bottom']['admin_menu']['#attached']; |
74 | 92 |
$options = array('every_page' => TRUE); |
75 | 93 |
|
76 |
// @todo Stop-gap fix until cached rendering is resolved. |
|
77 |
// @see http://drupal.org/node/1567622 |
|
94 |
// @todo Stop-gap fix until cached rendering is resolved (http://drupal.org/node/1567622). |
|
78 | 95 |
if (module_exists('shortcut')) { |
79 | 96 |
$attached['css'][drupal_get_path('module', 'shortcut') . '/shortcut.css'] = $options; |
80 | 97 |
} |
... | ... | |
134 | 151 |
*/ |
135 | 152 |
function adminimal_admin_menu_admin_menu_output_build(&$content) { |
136 | 153 |
|
137 |
if (variable_get('adminimal_admin_menu_render', 'collapsed') != 'hidden') { |
|
154 |
// Shortcut menu. |
|
155 |
if (module_exists('shortcut') && variable_get('adminimal_admin_menu_render', 'collapsed') != 'hidden') { |
|
138 | 156 |
// Add shortcuts bar. |
139 | 157 |
$content['shortcut'] = array( |
140 | 158 |
'#access' => module_exists('shortcut'), |
... | ... | |
151 | 169 |
'#pre_render' => array('shortcut_toolbar_pre_render'), |
152 | 170 |
); |
153 | 171 |
} |
154 |
|
|
155 | 172 |
} |
156 | 173 |
|
157 | 174 |
/** |
... | ... | |
171 | 188 |
$page['#attributes']['class'][] = 'adminimal-menu'; |
172 | 189 |
|
173 | 190 |
// Hide the menu. |
174 |
if (variable_get('adminimal_admin_menu_render', 'collapsed') == 'exclusive') { |
|
191 |
if (module_exists('shortcut') && variable_get('adminimal_admin_menu_render', 'collapsed') == 'exclusive') {
|
|
175 | 192 |
unset($content['icon']['icon']); |
176 | 193 |
unset($content['search']); |
177 | 194 |
foreach ($content['menu'] as $key => $link) { |
... | ... | |
205 | 222 |
$content['responsive-menu'] = $responsivemenu; |
206 | 223 |
|
207 | 224 |
// Create the responsive shortucts. |
208 |
$content['responsive']['shortcuts'] = array( |
|
209 |
'#prefix' => '<div id="admin-menu-shortcuts-responsive">', |
|
210 |
'#suffix' => '</div>', |
|
211 |
'#pre_render' => array('shortcut_toolbar_pre_render'), |
|
212 |
); |
|
225 |
if (module_exists('shortcut')) { |
|
226 |
$content['responsive']['shortcuts'] = array( |
|
227 |
'#prefix' => '<div id="admin-menu-shortcuts-responsive">', |
|
228 |
'#suffix' => '</div>', |
|
229 |
'#pre_render' => array('shortcut_toolbar_pre_render'), |
|
230 |
); |
|
231 |
} |
|
213 | 232 |
} |
214 | 233 |
} |
215 | 234 |
|
... | ... | |
220 | 239 |
if (!_adminimal_admin_menu_access()) { |
221 | 240 |
return; |
222 | 241 |
} |
242 |
|
|
223 | 243 |
// Add the "adminimal" class to the body for better css selection. |
224 | 244 |
$vars['classes_array'][] = 'adminimal-menu'; |
225 | 245 |
|
... | ... | |
232 | 252 |
} |
233 | 253 |
|
234 | 254 |
// Add the shortcut render mode class. |
235 |
$vars['classes_array'][] = 'menu-render-' . variable_get('adminimal_admin_menu_render', 'collapsed'); |
|
236 |
|
|
237 |
/* |
|
238 |
* Fix the viewport, correcting the mobile device zoom. |
|
239 |
* |
|
240 |
* @todo Maybe remove this and let the theme manage the view point. |
|
241 |
* But i was suprised that only few "responsive" drupal themes were fixing |
|
242 |
* the viewport. |
|
243 |
*/ |
|
244 |
$viewport = array( |
|
245 |
'#tag' => 'meta', |
|
246 |
'#attributes' => array( |
|
247 |
'name' => 'viewport', |
|
248 |
'content' => 'width=device-width, initial-scale=1, maximum-scale=1', |
|
249 |
), |
|
250 |
); |
|
251 |
drupal_add_html_head($viewport, 'viewport'); |
|
255 |
if (module_exists('shortcut')) { |
|
256 |
$vars['classes_array'][] = 'menu-render-' . variable_get('adminimal_admin_menu_render', 'collapsed'); |
|
257 |
} |
|
258 |
|
|
259 |
_adminimal_admin_menu_viewport(); |
|
260 |
} |
|
252 | 261 |
|
262 |
/** |
|
263 |
* Add viewport for scaling on devices. |
|
264 |
*/ |
|
265 |
function _adminimal_admin_menu_viewport() { |
|
266 |
$use_slicknav = variable_get('adminimal_admin_menu_slicknav', TRUE); |
|
267 |
$use_viewport = variable_get('adminimal_admin_menu_viewport', TRUE); |
|
268 |
|
|
269 |
// Only needed for slicknav. |
|
270 |
if ($use_slicknav && $use_viewport) { |
|
271 |
$viewport = array( |
|
272 |
'#tag' => 'meta', |
|
273 |
'#attributes' => array( |
|
274 |
'name' => 'viewport', |
|
275 |
'content' => 'width=device-width, initial-scale=1', |
|
276 |
), |
|
277 |
); |
|
278 |
drupal_add_html_head($viewport, 'viewport'); |
|
279 |
} |
|
253 | 280 |
} |
254 | 281 |
|
255 | 282 |
/** |
drupal7/sites/all/modules/adminimal_admin_menu/adminimal_menu_settings.inc | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
/** |
|
4 |
* @file |
|
5 |
* Menu builder functions for Administration menu. |
|
6 |
*/ |
|
7 |
|
|
8 |
/** |
|
9 |
* Create the settings page form. |
|
10 |
*/ |
|
11 |
function adminimal_admin_menu_settings($form, &$form_state) { |
|
12 |
|
|
13 |
// Create the shortcut category. |
|
14 |
$form['shortcuts'] = array( |
|
15 |
'#type' => 'fieldset', |
|
16 |
'#title' => t('Shortcut options'), |
|
17 |
); |
|
18 |
|
|
19 |
// Create the select list. |
|
20 |
$form['shortcuts']['adminimal_admin_menu_render'] = array( |
|
21 |
'#type' => 'select', |
|
22 |
'#title' => t('Rendering method'), |
|
23 |
'#default_value' => variable_get('adminimal_admin_menu_render', 'collapsed'), |
|
24 |
'#options' => array( |
|
25 |
'hidden' => t('Hidden'), |
|
26 |
'inline' => t('Inline'), |
|
27 |
'collapsed' => t('Collapsed'), |
|
28 |
'newline' => t('Newline'), |
|
29 |
'dropdown' => t('Dropdown'), |
|
30 |
'exclusive' => t('Exclusive'), |
|
31 |
), |
|
32 |
'#description' => t('Select how shortcuts will be rendered: <ul> <li>Hidden: Shortcuts will not be rendered inside the admin menu.</li> <li>Inline: Shortcuts will be rendered on the same line with the root menu links.</li> <li>Collapsed: Shortcuts will be collapsed like a normal menu. <strong>(Default option)</strong></li> <li>Newline: Shortcuts will be rendered on a new line. Below the root menu links.</li> <li>Dropdown: Shortcuts will be rendered inside a dropdown using the select html tag.</li> <li>Exclusive: Only the shortcuts will be rendered; the normal menu will be hidden.</li></ul>'), |
|
33 |
'#required' => TRUE, |
|
34 |
); |
|
35 |
|
|
36 |
// Create the advanced settings category. |
|
37 |
$form['advanced_settings'] = array( |
|
38 |
'#type' => 'fieldset', |
|
39 |
'#title' => t('Advanced Settings'), |
|
40 |
'#description' => '<div class="messages warning">WARNING: Do not change any of the advanced setting unless you know what you are doing!</div>', |
|
41 |
); |
|
42 |
|
|
43 |
$form['advanced_settings']['adminimal_admin_menu_slicknav'] = array( |
|
44 |
'#type' => 'checkbox', |
|
45 |
'#default_value' => variable_get('adminimal_admin_menu_slicknav', TRUE), |
|
46 |
'#title' => t('Enable Responsive Menu.'), |
|
47 |
'#description' => t('<strong>Default value => Checked</strong>. |
|
48 |
Enable this option if you want to have responsive menu and mobile device support. |
|
49 |
While disabling this option could save you few kilobytes (around 3KB), it will completely disable the responsive menu functionality.'), |
|
50 |
); |
|
51 |
|
|
52 |
$form['advanced_settings']['adminimal_admin_menu_jquery'] = array( |
|
53 |
'#type' => 'checkbox', |
|
54 |
'#default_value' => variable_get('adminimal_admin_menu_jquery', TRUE), |
|
55 |
'#title' => t('Load the required jQuery 1.7 library automagically.'), |
|
56 |
'#description' => t('<strong>Default value => Checked</strong>. This will load the newer jQuery version 1.7 using |
|
57 |
the no-conflict method so it won\'t interfere with any existing jQuery or other JavaScript libraries. |
|
58 |
The only reason to un-check this if you are already using a newer version of jQuery site-wide and its globally accessible by the "$" variable. |
|
59 |
Un-cheking this option could save you 33KB, but it may also break your JavaScript if not used correctly.'), |
|
60 |
'#states' => array( |
|
61 |
// Hide the settings when the cancel notify checkbox is disabled. |
|
62 |
'visible' => array( |
|
63 |
':input[name="adminimal_admin_menu_slicknav"]' => array('checked' => TRUE), |
|
64 |
), |
|
65 |
'unchecked' => array( |
|
66 |
variable_get('adminimal_admin_menu_jquery', TRUE) => FALSE, |
|
67 |
), |
|
68 |
), |
|
69 |
); |
|
70 |
|
|
71 |
// Create the submit button. |
|
72 |
$form['submit'] = array( |
|
73 |
'#type' => 'submit', |
|
74 |
'#value' => t('Save configuration'), |
|
75 |
); |
|
76 |
|
|
77 |
return $form; |
|
78 |
|
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Submit handler for views_sexy_throbber_settings(). |
|
83 |
*/ |
|
84 |
function adminimal_admin_menu_settings_submit($form, &$form_state) { |
|
85 |
|
|
86 |
// Exclude unnecessary elements. |
|
87 |
form_state_values_clean($form_state); |
|
88 |
|
|
89 |
foreach ($form_state['values'] as $key => $value) { |
|
90 |
if (is_array($value) && isset($form_state['values']['array_filter'])) { |
|
91 |
$value = array_keys(array_filter($value)); |
|
92 |
} |
|
93 |
variable_set($key, $value); |
|
94 |
} |
|
95 |
|
|
96 |
// Clear the admin menu cache. |
|
97 |
admin_menu_flush_caches(); |
|
98 |
|
|
99 |
// Display a message to the user. |
|
100 |
drupal_set_message(t('The configuration options have been saved.')); |
|
101 |
} |
drupal7/sites/all/modules/shs/README.txt | ||
---|---|---|
22 | 22 |
"Simple hierarchical select" as widget type. |
23 | 23 |
|
24 | 24 |
* Field settings |
25 |
- "Display number of nodes" |
|
26 |
Displays the number of nodes associated to a term next to the term name in |
|
27 |
the dropdown. |
|
28 |
WARNING: on sites with a lot of terms and nodes this can be a great |
|
29 |
performance killer (even if the data is cached). |
|
30 | 25 |
- "Allow creating new terms" |
31 | 26 |
Terms may be created directly from within the dropdowns (user needs to have |
32 | 27 |
permission to create terms in the vocabulary). |
... | ... | |
73 | 68 |
custom handler to avoid loading of all Drupal functions and speed up |
74 | 69 |
loading. |
75 | 70 |
|
71 |
* Entity reference (https://www.drupal.org/project/entityreference) |
|
72 |
- "Simple hierarchical select" works out of the box with simple entity |
|
73 |
reference fields. In case you use Views as entity selection mode for your |
|
74 |
field there may be some problems, though. |
|
75 |
Your reference view needs at least one filter for the vocabulary. Otherwise |
|
76 |
"Simple hierarchical select" has no chance to retrieve the list of possible |
|
77 |
options to display. |
|
78 |
More complex reference views may cause "Simple hierarchical select" to fail, |
|
79 |
so its best to keep it as simple as possible. |
|
80 |
|
|
76 | 81 |
|
77 | 82 |
-- CONTACT -- |
78 | 83 |
|
drupal7/sites/all/modules/shs/includes/handlers/shs_handler_filter_entityreference.inc | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
/** |
|
4 |
* @file |
|
5 |
* Definition of shs_handler_filter_numeric. |
|
6 |
*/ |
|
7 |
|
|
8 |
/** |
|
9 |
* Extends simple numeric filter with hierarchical selection. |
|
10 |
* |
|
11 |
* @ingroup views_filter_handlers |
|
12 |
*/ |
|
13 |
class shs_handler_filter_entityreference extends views_handler_filter_numeric { |
|
14 |
|
|
15 |
// Define filter options. |
|
16 |
function option_definition() { |
|
17 |
$options = parent::option_definition(); |
|
18 |
|
|
19 |
$options['shs_enabled'] = array('default' => FALSE); |
|
20 |
$options['use_chosen'] = array('default' => 'never'); |
|
21 |
|
|
22 |
return $options; |
|
23 |
} |
|
24 |
|
|
25 |
/** |
|
26 |
* Build the options form. |
|
27 |
* |
|
28 |
* @param array $form |
|
29 |
* Current form structure. |
|
30 |
* @param array $form_state |
|
31 |
* Current form state. |
|
32 |
*/ |
|
33 |
function options_form(&$form, &$form_state) { |
|
34 |
parent::options_form($form, $form_state); |
|
35 |
|
|
36 |
$form['shs_enabled'] = array( |
|
37 |
'#type' => 'checkbox', |
|
38 |
'#title' => t('Output filter as hierarchical select'), |
|
39 |
'#default_value' => $this->options['shs_enabled'], |
|
40 |
); |
|
41 |
|
|
42 |
if (module_exists('chosen')) { |
|
43 |
$form['use_chosen'] = array( |
|
44 |
'#type' => 'select', |
|
45 |
'#title' => t('Output this field with !chosen', array('!chosen' => l(t('Chosen'), 'http://drupal.org/project/chosen'))), |
|
46 |
'#description' => t('Select in which cases the element will use the !chosen module for the term selection of each level.', array('!chosen' => l(t('Chosen'), 'http://drupal.org/project/chosen'))), |
|
47 |
'#default_value' => empty($this->options['use_chosen']) ? 'never' : $this->options['use_chosen'], |
|
48 |
'#dependency' => array( |
|
49 |
'edit-options-shs-enabled' => array(1), |
|
50 |
), |
|
51 |
'#options' => array( |
|
52 |
'chosen' => t('let chosen decide'), |
|
53 |
'always' => t('always'), |
|
54 |
'never' => t('never'), |
|
55 |
), |
|
56 |
); |
|
57 |
} |
|
58 |
} |
|
59 |
|
|
60 |
/** |
|
61 |
* Provide a simple textfield for equality |
|
62 |
*/ |
|
63 |
function value_form(&$form, &$form_state) { |
|
64 |
global $language; |
|
65 |
|
|
66 |
parent::value_form($form, $form_state); |
|
67 |
if (empty($form_state['exposed']) || empty($this->options['shs_enabled'])) { |
|
68 |
return; |
|
69 |
} |
|
70 |
|
|
71 |
$identifier = $this->options['expose']['identifier']; |
|
72 |
$multiple = $this->options['expose']['multiple']; |
|
73 |
|
|
74 |
$field = field_info_field($this->definition['field_name']); |
|
75 |
$handler = entityreference_get_selection_handler($field); |
|
76 |
$referencable_entities = $handler->getReferencableEntities(); |
|
77 |
$vocabulary_names = array(); |
|
78 |
if ('views' === $field['settings']['handler']) { |
|
79 |
$view_settings = $field['settings']['handler_settings']['view']; |
|
80 |
// Try to load vocabularies from view filter. |
|
81 |
$vocabulary_names = _shs_entityreference_views_get_vocabularies($view_settings['view_name'], $view_settings['display_name']); |
|
82 |
} |
|
83 |
else { |
|
84 |
$vocabulary_names = empty($field['settings']['handler_settings']['target_bundles']) ? array() : $field['settings']['handler_settings']['target_bundles']; |
|
85 |
} |
|
86 |
$vocabularies = array(); |
|
87 |
foreach ($vocabulary_names as $vocabulary_name) { |
|
88 |
if (($vocabulary = taxonomy_vocabulary_machine_name_load($vocabulary_name)) !== FALSE) { |
|
89 |
$vocabularies[] = $vocabulary; |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
if (empty($form_state['input'][$identifier])) { |
|
94 |
$form_state['input'][$identifier] = 'All'; |
|
95 |
} |
|
96 |
$default_value = $form_state['input'][$identifier]; |
|
97 |
if (!is_array($default_value) && $multiple) { |
|
98 |
$default_value = explode('+', $default_value); |
|
99 |
foreach ($default_value as $delta => $value) { |
|
100 |
$default_value[$delta] = explode(',', $value); |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
$parents = array(); |
|
105 |
if (!empty($default_value) && $default_value != 'All') { |
|
106 |
if (is_array($default_value) && $default_value[0] != 'All') { |
|
107 |
foreach ($default_value as $delta => $level) { |
|
108 |
$parents[$delta]['tid'] = $level; |
|
109 |
} |
|
110 |
} |
|
111 |
elseif (is_string($default_value)) { |
|
112 |
$term_parents = taxonomy_get_parents_all($default_value); |
|
113 |
// Remove selected term from list. |
|
114 |
array_shift($term_parents); |
|
115 |
foreach (array_reverse($term_parents) as $term) { |
|
116 |
$parents[] = array('tid' => $term->tid); |
|
117 |
} |
|
118 |
// Add current term (name not needed). |
|
119 |
$parents[] = array('tid' => $default_value); |
|
120 |
} |
|
121 |
} |
|
122 |
|
|
123 |
// Add fake item for next level. |
|
124 |
$parents[] = array('tid' => 0); |
|
125 |
|
|
126 |
$element_settings = array( |
|
127 |
'create_new_terms' => FALSE, |
|
128 |
'create_new_levels' => FALSE, |
|
129 |
'required' => FALSE, |
|
130 |
'language' => $language, |
|
131 |
); |
|
132 |
if (module_exists('chosen') && !empty($this->options['use_chosen'])) { |
|
133 |
$element_settings['use_chosen'] = $this->options['use_chosen']; |
|
134 |
} |
|
135 |
if (!empty($this->options['exposed']) && !empty($this->options['expose']['required'])) { |
|
136 |
$element_settings['required'] = TRUE; |
|
137 |
} |
|
138 |
// Allowing other modules to add settings for shs. |
|
139 |
if (!empty($this->options['expose']['shs'])) { |
|
140 |
$element_settings = array_merge($element_settings, $this->options['expose']['shs']); |
|
141 |
} |
|
142 |
|
|
143 |
$vocabulary_identifier = array( |
|
144 |
'field_name' => $field['field_name'], |
|
145 |
); |
|
146 |
if (count($vocabularies) == 1) { |
|
147 |
// Get ID from first (and only) vocabulary. |
|
148 |
$vocabulary_identifier = $vocabularies[0]->vid; |
|
149 |
} |
|
150 |
|
|
151 |
// Generate a random hash to avoid merging of settings by drupal_add_js. |
|
152 |
// This is necessary until http://drupal.org/node/208611 lands for D7. |
|
153 |
$js_hash = _shs_create_hash(); |
|
154 |
// Create settings needed for our js magic. |
|
155 |
$settings_js = array( |
|
156 |
'shs' => array( |
|
157 |
$identifier => array( |
|
158 |
$js_hash => array( |
|
159 |
'vid' => $vocabulary_identifier, |
|
160 |
'settings' => $element_settings, |
|
161 |
'default_value' => $default_value, |
|
162 |
'parents' => $parents, |
|
163 |
'multiple' => $multiple, |
|
164 |
'any_label' => variable_get('views_exposed_filter_any_label', 'new_any') == 'old_any' ? t('<Any>') : t('- Any -'), |
|
165 |
'any_value' => 'All', |
|
166 |
), |
|
167 |
), |
|
168 |
), |
|
169 |
); |
|
170 |
// Add settings. |
|
171 |
drupal_add_js($settings_js, 'setting'); |
|
172 |
// Add behavior. |
|
173 |
drupal_add_js(drupal_get_path('module', 'shs') . '/js/shs.js'); |
|
174 |
|
|
175 |
if (is_array($default_value) && $multiple && $default_value[0] != 'All') { |
|
176 |
foreach ($default_value as $delta => $level) { |
|
177 |
if ($delta == 0) { |
|
178 |
$default_value_str = implode(',', $level); |
|
179 |
} |
|
180 |
else { |
|
181 |
$default_value_str .= '+' . implode(',', $level); |
|
182 |
} |
|
183 |
} |
|
184 |
} |
|
185 |
|
|
186 |
$options = array(); |
|
187 |
foreach ($referencable_entities as $terms) { |
|
188 |
$options += $terms; |
|
189 |
} |
|
190 |
// Change type of value element. |
|
191 |
$form['value']['#type'] = 'select'; |
|
192 |
$form['value']['#options'] = $options; |
|
193 |
$form['value']['#size'] = 1; |
|
194 |
$form['value']['#default_value'] = empty($default_value) ? 'All' : $default_value; |
|
195 |
$form['value']['#attributes'] = array( |
|
196 |
'class' => array('element-invisible', 'shs-enabled'), |
|
197 |
); |
|
198 |
|
|
199 |
if (!empty($form_state['exposed']) && isset($identifier) && empty($form_state['input'][$identifier]) || $multiple && isset($form_state['input'][$identifier][0])) { |
|
200 |
$form_state['input'][$identifier] = empty($default_value_str) ? 'All' : $default_value_str; |
|
201 |
} |
|
202 |
} |
|
203 |
|
|
204 |
/** |
|
205 |
* Function to build the admin summary. |
|
206 |
* |
|
207 |
* @return string |
|
208 |
* Short summary explaining the settings. |
|
209 |
*/ |
|
210 |
function admin_summary() { |
|
211 |
$summary = parent::admin_summary(); |
|
212 |
|
|
213 |
// @todo: add "shs". |
|
214 |
return $summary; |
|
215 |
} |
|
216 |
|
|
217 |
} |
drupal7/sites/all/modules/shs/includes/handlers/shs_handler_filter_term_node_tid.inc | ||
---|---|---|
45 | 45 |
} |
46 | 46 |
|
47 | 47 |
function value_form(&$form, &$form_state) { |
48 |
global $language; |
|
49 |
|
|
48 | 50 |
parent::value_form($form, $form_state); |
49 | 51 |
|
50 | 52 |
$multiple = $this->options['expose']['multiple']; |
... | ... | |
64 | 66 |
|
65 | 67 |
if (!empty($form_state['input'][$identifier])) { |
66 | 68 |
$default_value = $form_state['input'][$identifier]; |
67 |
if (!is_array($default_value) && $multiple) { |
|
68 |
$default_value = explode('+', $default_value); |
|
69 |
foreach ($default_value as $delta => $value) { |
|
70 |
$default_value[$delta] = explode(',', $value); |
|
71 |
} |
|
69 |
if ($multiple && !is_array($default_value)) { |
|
70 |
$default_value = array($default_value); |
|
72 | 71 |
} |
73 | 72 |
} |
74 | 73 |
|
75 | 74 |
$parents = array(); |
76 | 75 |
if (!empty($default_value) && $default_value != 'All') { |
77 | 76 |
if (is_array($default_value) && $default_value[0] != 'All') { |
78 |
foreach ($default_value as $delta => $level) { |
|
79 |
foreach ($level as $tid) { |
|
80 |
$parents[$delta]['tid'] = $level; |
|
77 |
if (strpos($default_value[0], ',') !== FALSE || strpos($default_value[0], '+') !== FALSE) { |
|
78 |
$values = array(); |
|
79 |
foreach ($default_value as $default) { |
|
80 |
$values += preg_split('/[,\+]+/', $default, -1, PREG_SPLIT_NO_EMPTY); |
|
81 | 81 |
} |
82 |
$form_state['input'][$identifier] = empty($values) ? 'All' : $values; |
|
83 |
$default_value = $values; |
|
84 |
} |
|
85 |
$parents_multiple = array(); |
|
86 |
foreach ($default_value as $delta => $tid) { |
|
87 |
$parents_multiple[] = $tid; |
|
82 | 88 |
} |
89 |
$parents[] = array('tid' => $parents_multiple); |
|
83 | 90 |
} |
84 | 91 |
elseif (is_string($default_value)) { |
85 | 92 |
$term_parents = taxonomy_get_parents_all($default_value); |
... | ... | |
100 | 107 |
'create_new_terms' => FALSE, |
101 | 108 |
'create_new_levels' => FALSE, |
102 | 109 |
'required' => FALSE, |
110 |
'language' => $language, |
|
103 | 111 |
); |
104 | 112 |
if (module_exists('chosen') && !empty($this->options['use_chosen'])) { |
105 | 113 |
$element_settings['use_chosen'] = $this->options['use_chosen']; |
... | ... | |
107 | 115 |
if (!empty($this->options['exposed']) && !empty($this->options['expose']['required'])) { |
108 | 116 |
$element_settings['required'] = TRUE; |
109 | 117 |
} |
118 |
// Allowing other modules to add settings for shs. |
|
119 |
if (!empty($this->options['expose']['shs'])) { |
|
120 |
$element_settings = array_merge($element_settings, $this->options['expose']['shs']); |
|
121 |
} |
|
110 | 122 |
|
111 | 123 |
// Generate a random hash to avoid merging of settings by drupal_add_js. |
112 | 124 |
// This is necessary until http://drupal.org/node/208611 lands for D7. |
... | ... | |
114 | 126 |
// Create settings needed for our js magic. |
115 | 127 |
$settings_js = array( |
116 | 128 |
'shs' => array( |
117 |
$identifier => array( |
|
129 |
$identifier . ($multiple ? '[]' : '') => array(
|
|
118 | 130 |
$js_hash => array( |
119 | 131 |
'vid' => $vocabulary->vid, |
120 | 132 |
'settings' => $element_settings, |
121 | 133 |
'default_value' => $default_value, |
122 | 134 |
'parents' => $parents, |
123 | 135 |
'multiple' => $multiple, |
136 |
'any_label' => variable_get('views_exposed_filter_any_label', 'new_any') == 'old_any' ? t('<Any>') : t('- Any -'), |
|
137 |
'any_value' => 'All', |
|
124 | 138 |
), |
125 | 139 |
), |
126 | 140 |
), |
127 | 141 |
); |
142 |
drupal_alter(array('shs_js_settings', "shs_{$identifier}_js_settings"), $settings_js, $identifier, $vocabulary->vid); |
|
128 | 143 |
// Add settings. |
129 | 144 |
drupal_add_js($settings_js, 'setting'); |
130 | 145 |
// Add behavior. |
131 | 146 |
drupal_add_js(drupal_get_path('module', 'shs') . '/js/shs.js'); |
132 | 147 |
|
133 |
if (is_array($default_value) && $multiple && $default_value[0] != 'All') { |
|
134 |
foreach ($default_value as $delta => $level) { |
|
135 |
if ($delta == 0) { |
|
136 |
$default_value_str = implode(',', $level); |
|
137 |
} |
|
138 |
else { |
|
139 |
$default_value_str .= '+' . implode(',', $level); |
|
140 |
} |
|
141 |
} |
|
142 |
} |
|
143 |
|
|
144 |
// Rewrite default select to textfield. |
|
145 |
$form['value'] = array( |
|
146 |
'#type' => 'textfield', |
|
147 |
'#default_value' => empty($default_value_str) ? 'All' : $default_value_str, |
|
148 |
// Rewrite default select element. |
|
149 |
$form['value'] += array( |
|
148 | 150 |
'#attributes' => array( |
149 | 151 |
'class' => array('element-invisible', 'shs-enabled'), |
150 | 152 |
), |
151 | 153 |
); |
152 |
|
|
153 |
if (!empty($form_state['exposed']) && isset($identifier) && empty($form_state['input'][$identifier]) || $multiple && isset($form_state['input'][$identifier][0])) { |
|
154 |
$form_state['input'][$identifier] = empty($default_value_str) ? 'All' : $default_value_str; |
|
155 |
} |
|
156 | 154 |
} |
157 | 155 |
|
158 | 156 |
if (empty($form_state['exposed'])) { |
drupal7/sites/all/modules/shs/includes/handlers/shs_handler_filter_term_node_tid_depth.inc | ||
---|---|---|
87 | 87 |
} |
88 | 88 |
|
89 | 89 |
// Now build the subqueries. |
90 |
$subquery = db_select('taxonomy_index', 'tn'); |
|
91 |
$subquery->addField('tn', 'nid'); |
|
90 |
if (module_exists('taxonomy_entity_index')) { |
|
91 |
$subquery = db_select('taxonomy_entity_index', 'tn'); |
|
92 |
$subquery->addField('tn', 'entity_id'); |
|
93 |
} |
|
94 |
else { |
|
95 |
$subquery = db_select('taxonomy_index', 'tn'); |
|
96 |
$subquery->addField('tn', 'nid'); |
|
97 |
} |
|
92 | 98 |
$where = db_or()->condition('tn.tid', $this->value, $operator); |
93 | 99 |
$last = "tn"; |
94 | 100 |
|
drupal7/sites/all/modules/shs/js/shs.js | ||
---|---|---|
3 | 3 |
* Custom behaviors for Simple hierarchical select. |
4 | 4 |
*/ |
5 | 5 |
|
6 |
(function ($) { |
|
6 |
(function ($, Drupal) {
|
|
7 | 7 |
|
8 | 8 |
/** |
9 | 9 |
* Creates the widget for Simple hierarchical select. |
... | ... | |
13 | 13 |
// Default function to attach the behavior. |
14 | 14 |
attach: function (context, settings) { |
15 | 15 |
var self = this; |
16 |
$('input.shs-enabled') |
|
17 |
.not('.shs-processed') |
|
16 |
var settingsDefault = { |
|
17 |
display: { |
|
18 |
animationSpeed: 400, |
|
19 |
} |
|
20 |
}; |
|
21 |
$('select.shs-enabled:not([disabled])') |
|
18 | 22 |
.once('shs') |
19 | 23 |
.addClass('element-invisible') |
24 |
.hide() |
|
20 | 25 |
.each(function() { |
21 |
var $field = $(this);
|
|
26 |
$field = $(this); |
|
22 | 27 |
var fieldName = $(this).attr('name'); |
28 |
// Multiform messes up the names of the fields |
|
29 |
// to the format multiform[something][fieldname][...]. |
|
30 |
if (fieldName.indexOf('multiform') == 0) { |
|
31 |
var split = fieldName.split(']['); |
|
32 |
split.splice(0, 1); |
|
33 |
fieldName = split.splice(0, 1) + '[' + split.join(']['); |
|
34 |
} |
|
23 | 35 |
|
24 | 36 |
if (fieldName in settings.shs) { |
25 | 37 |
var fieldSettings = {}; |
... | ... | |
29 | 41 |
$.each(settings.shs[fieldName], function(hash, setting) { |
30 | 42 |
fieldSettings = setting; |
31 | 43 |
}); |
44 |
fieldSettings = $.extend({}, fieldSettings, settingsDefault, { |
|
45 |
fieldName: fieldName |
|
46 |
}); |
|
32 | 47 |
var level = 0; |
33 | 48 |
var parent_id = 0; |
34 | 49 |
// Update class of wrapper element. |
... | ... | |
42 | 57 |
// Add error-class if there was an error with the original field. |
43 | 58 |
$select.addClass('error'); |
44 | 59 |
} |
60 |
// Add label to dropdown. |
|
61 |
$label = shsLabelCreate($field.attr('id'), fieldSettings, level); |
|
62 |
if ($label !== false) { |
|
63 |
$label.appendTo($field.parent()); |
|
64 |
} |
|
45 | 65 |
$select.appendTo($field.parent()); |
46 | 66 |
// Retrieve data for this level. |
47 | 67 |
getTermChildren($select, fieldSettings, parent_id, parent.tid, $field.attr('id')); |
... | ... | |
54 | 74 |
} |
55 | 75 |
}); |
56 | 76 |
var addNextLevel = false; |
57 |
if ((level > 1 || parent_id) && (fieldSettings.settings.create_new_terms && fieldSettings.settings.create_new_levels)) {
|
|
77 |
if ((level > 1 || parent_id) && ((fieldSettings.settings.create_new_terms && fieldSettings.settings.create_new_levels) || fieldSettings.settings.test_create_new_levels)) {
|
|
58 | 78 |
// Add next level in hierarchy if new levels may be created. |
59 | 79 |
addNextLevel = true; |
60 | 80 |
} |
61 |
if (fieldSettings.default_value && (fieldSettings.default_value.tid == parent_id)) {
|
|
81 |
if (fieldSettings.default_value && (fieldSettings.default_value === parent_id) && (fieldSettings.default_value !== '')) {
|
|
62 | 82 |
addNextLevel = true; |
63 | 83 |
} |
64 | 84 |
if (addNextLevel) { |
85 |
// Add label to dropdown. |
|
86 |
$label = shsLabelCreate($field.attr('id'), fieldSettings, level); |
|
87 |
if ($label !== false) { |
|
88 |
$label.appendTo($field.parent()); |
|
89 |
} |
|
65 | 90 |
// Try to add one additional level. |
66 |
$select = shsElementCreate($field.attr('id'), fieldSettings, level); |
|
91 |
$select = shsElementCreate($field.attr('id'), fieldSettings, ++level);
|
|
67 | 92 |
$select.appendTo($field.parent()); |
68 | 93 |
// Retrieve data for this level. |
69 | 94 |
getTermChildren($select, fieldSettings, parent_id, 0, $field.attr('id')); |
... | ... | |
88 | 113 |
* ID of original field which is rewritten as "taxonomy_shs". |
89 | 114 |
*/ |
90 | 115 |
getTermChildren = function($element, settings, parent_value, default_value, base_id) { |
91 |
|
|
92 | 116 |
// Check if parent_value is number and convert it. |
93 | 117 |
if (!$.isArray(parent_value) && typeof parent_value != "object") { |
94 | 118 |
parent_value = [parent_value]; |
95 | 119 |
} |
96 | 120 |
|
97 |
// Check if default_value is object and convert it. |
|
98 |
if (!$.isArray(default_value) && typeof default_value == "object") { |
|
99 |
var arr = new Array; |
|
100 |
$.each(default_value, function(delta, value){ |
|
101 |
arr.push(value); |
|
102 |
}); |
|
103 |
default_value = arr; |
|
104 |
} |
|
105 |
|
|
106 | 121 |
$.ajax({ |
107 |
url: Drupal.settings.basePath + 'js/shs/json', |
|
122 |
url: Drupal.settings.basePath + '?q=' + Drupal.settings.pathPrefix + 'js/shs/json',
|
|
108 | 123 |
type: 'POST', |
109 | 124 |
dataType: 'json', |
110 | 125 |
cache: true, |
... | ... | |
113 | 128 |
arguments: { |
114 | 129 |
vid: settings.vid, |
115 | 130 |
parent: parent_value, |
116 |
settings: settings.settings |
|
131 |
settings: settings.settings, |
|
132 |
field: settings.fieldName |
|
117 | 133 |
} |
118 | 134 |
}, |
119 | 135 |
success: function(data) { |
... | ... | |
125 | 141 |
var options = $element.attr('options'); |
126 | 142 |
} |
127 | 143 |
|
128 |
if (data.data.length == 0 && !(settings.settings.create_new_terms && (settings.settings.create_new_levels || (parent_value + default_value == 0)))) {
|
|
144 |
if (((data.data.length == 0) || ((data.data.length == 1 && !data.data[0].tid))) && !(settings.settings.create_new_terms && (settings.settings.create_new_levels || (parent_value[0] == settings.any_value && default_value == 0)))) {
|
|
129 | 145 |
// Remove element. |
146 |
$element.prev('label').remove(); |
|
130 | 147 |
$element.remove(); |
131 | 148 |
return; |
132 | 149 |
} |
133 | 150 |
|
134 | 151 |
// Remove all existing options. |
135 | 152 |
$('option', $element).remove(); |
136 |
// Add empty option (if field is not required and not multiple |
|
137 |
// or this is not the first level and not multiple). |
|
138 |
if (!settings.settings.required || (settings.settings.required && parent_value != 0 && !settings.multiple)) { |
|
139 |
options[options.length] = new Option(Drupal.t('- None -'), 0); |
|
140 |
} |
|
141 |
|
|
142 |
if (settings.settings.create_new_terms) { |
|
143 |
// Add option to add new item. |
|
144 |
options[options.length] = new Option(Drupal.t('<Add new item>', {}, {context: 'shs'}), '_add_new_'); |
|
153 |
// Add empty option (if field is not required or this is not the |
|
154 |
// first level. |
|
155 |
if (!settings.settings.required || (settings.settings.required && (default_value === 0 || parent_value !== 0))) { |
|
156 |
options[options.length] = new Option(settings.any_label, settings.any_value); |
|
145 | 157 |
} |
146 | 158 |
|
147 | 159 |
// Add retrieved list of options. |
148 | 160 |
$.each(data.data, function(key, term) { |
149 |
options[options.length] = new Option(term.label, term.tid); |
|
161 |
if (term.vid && settings.settings.create_new_terms) { |
|
162 |
// Add option to add new item. |
|
163 |
options[options.length] = new Option(Drupal.t('<Add new item>', {}, {context: 'shs'}), '_add_new_'); |
|
164 |
} |
|
165 |
else if (term.tid) { |
|
166 |
option = new Option(term.label, term.tid); |
|
167 |
options[options.length] = option; |
|
168 |
if (term.has_children) { |
|
169 |
option.setAttribute("class", "has-children"); |
|
170 |
} |
|
171 |
} |
|
150 | 172 |
}); |
151 | 173 |
// Set default value. |
152 | 174 |
$element.val(default_value); |
175 |
if (0 === default_value) { |
|
176 |
$element.val(settings.any_value); |
|
177 |
} |
|
153 | 178 |
|
154 | 179 |
// Try to convert the element to a "Chosen" element. |
155 | 180 |
if (!elementConvertToChosen($element, settings)) { |
156 | 181 |
// Display original dropdown element. |
157 |
$element.fadeIn(); |
|
182 |
$element.fadeIn(settings.display.animationSpeed);
|
|
158 | 183 |
$element.css('display','inline-block'); |
159 | 184 |
} |
185 |
else { |
|
186 |
$element.trigger('chosen:updated'); |
|
187 |
} |
|
160 | 188 |
|
161 | 189 |
// If there is no data, the field is required and the user is allowed |
162 | 190 |
// to add new terms, trigger click on "Add new". |
163 |
if (data.data.length == 0 && settings.settings.required && settings.settings.create_new_terms && (settings.settings.create_new_levels || (parent_value + default_value == 0))) {
|
|
191 |
if (data.data.length == 0 && settings.settings.required && settings.settings.create_new_terms && (settings.settings.create_new_levels || (parent_value[0] == settings.any_value && default_value == 0))) {
|
|
164 | 192 |
updateElements($element, base_id, settings, 1); |
165 | 193 |
} |
166 | 194 |
} |
... | ... | |
183 | 211 |
* ID of original field which is rewritten as "taxonomy_shs". |
184 | 212 |
* @param level |
185 | 213 |
* Current level in hierarchy. |
214 |
* @param settings |
|
215 |
* Field settings. |
|
186 | 216 |
*/ |
187 |
termAddNew = function($triggering_element, $container, term, base_id, level) { |
|
217 |
termAddNew = function($triggering_element, $container, term, base_id, level, settings) {
|
|
188 | 218 |
$.ajax({ |
189 |
url: Drupal.settings.basePath + 'js/shs/json', |
|
219 |
url: Drupal.settings.basePath + '?q=' + Drupal.settings.pathPrefix + 'js/shs/json',
|
|
190 | 220 |
type: 'POST', |
191 | 221 |
dataType: 'json', |
192 | 222 |
cache: true, |
... | ... | |
195 | 225 |
arguments: { |
196 | 226 |
vid: term.vid, |
197 | 227 |
parent: term.parent, |
198 |
name: term.name |
|
228 |
name: term.name, |
|
229 |
field: settings.fieldName |
|
199 | 230 |
} |
200 | 231 |
}, |
201 | 232 |
success: function(data) { |
... | ... | |
212 | 243 |
// Set new default value. |
213 | 244 |
$triggering_element.val(data.data.tid); |
214 | 245 |
// Set value of original field. |
215 |
updateFieldValue($triggering_element, base_id, level); |
|
246 |
updateFieldValue($triggering_element, base_id, level, settings); |
|
247 |
// Add new child element if adding new levels is allowed. |
|
248 |
if (settings.settings.create_new_levels) { |
|
249 |
$element_new = shsElementCreate(base_id, settings, level + 1); |
|
250 |
$element_new.appendTo($triggering_element.parent()); |
|
251 |
if ($element_new.prop) { |
|
252 |
var options_new = $element_new.prop('options'); |
|
253 |
} |
|
254 |
else { |
|
255 |
var options_new = $element_new.attr('options'); |
|
256 |
} |
|
257 |
// Add "none" option. |
|
258 |
options_new[options_new.length] = new Option(settings.any_label, settings.any_value); |
|
259 |
if (settings.settings.create_new_terms) { |
|
260 |
// Add option to add new item. |
|
261 |
options_new[options_new.length] = new Option(Drupal.t('<Add new item>', {}, {context: 'shs'}), '_add_new_'); |
|
262 |
} |
|
263 |
// Try to convert the element to a "Chosen" element. |
|
264 |
if (!elementConvertToChosen($element_new, settings)) { |
|
265 |
// Display original dropdown element. |
|
266 |
$element_new.fadeIn(settings.display.animationSpeed); |
|
267 |
$element_new.css('display','inline-block'); |
|
268 |
} |
|
269 |
} |
|
216 | 270 |
} |
217 | 271 |
}, |
218 | 272 |
error: function(xhr, status, error) { |
... | ... | |
221 | 275 |
}, |
222 | 276 |
complete: function(xhr, status) { |
223 | 277 |
// Remove container. |
278 |
$container.prev('label').remove(); |
|
224 | 279 |
$container.remove(); |
225 | 280 |
// Display triggering element. |
226 |
$triggering_element.fadeIn(); |
|
281 |
$triggering_element.fadeIn(settings.display.animationSpeed);
|
|
227 | 282 |
$triggering_element.css('display','inline-block'); |
283 |
$triggering_element.trigger('change'); |
|
228 | 284 |
} |
229 | 285 |
}); |
230 | 286 |
} |
... | ... | |
247 | 303 |
if (Drupal.settings.chosen) { |
248 | 304 |
// Remove element created by chosen. |
249 | 305 |
var elem_id = $(this).attr('id'); |
250 |
$('#' + elem_id.replace(/-/g, '_') + '_chzn').remove(); |
|
306 |
$element_chosen = $('#' + elem_id.replace(/-/g, '_') + '_chosen'); |
|
307 |
if ($element_chosen) { |
|
308 |
$element_chosen.prev('label').remove(); |
|
309 |
$element_chosen.remove(); |
|
310 |
} |
|
251 | 311 |
} |
252 | 312 |
// Remove element. |
313 |
$(this).prev('label').remove(); |
|
253 | 314 |
$(this).remove(); |
254 | 315 |
}); |
255 |
//$triggering_element.nextAll('.chzn-container').remove(); |
|
256 | 316 |
$triggering_element.nextAll('.shs-term-add-new-wrapper').remove(); |
257 | 317 |
// Create next level (if the value is != 0). |
258 | 318 |
if ($triggering_element.val() == '_add_new_') { |
259 | 319 |
// Hide element. |
260 | 320 |
$triggering_element.hide(); |
321 |
if (Drupal.settings.chosen) { |
|
322 |
// Remove element created by chosen. |
|
323 |
var elem_id = $triggering_element.attr('id'); |
|
324 |
$('#' + elem_id.replace(/-/g, '_') + '_chosen').remove(); |
|
325 |
} |
|
261 | 326 |
// Create new container with textfield and buttons ("cancel", "save"). |
262 | 327 |
$container = $('<div>') |
263 | 328 |
.addClass('shs-term-add-new-wrapper') |
... | ... | |
283 | 348 |
.bind('click', function(event) { |
284 | 349 |
event.preventDefault(); |
285 | 350 |
// Remove container. |
351 |
$container.prev('label').remove(); |
|
286 | 352 |
$container.remove(); |
287 | 353 |
// Reset value of triggering element. |
288 |
$triggering_element.val(0); |
|
289 |
// Display triggering element. |
|
290 |
$triggering_element.fadeIn(); |
|
291 |
$triggering_element.css('display','inline-block'); |
|
354 |
$triggering_element.val(settings.settings.any_value); |
|
355 |
|
|
356 |
if (!elementConvertToChosen($triggering_element, settings)) { |
|
357 |
// Display triggering element. |
|
358 |
$triggering_element.fadeIn(settings.display.animationSpeed); |
|
359 |
$triggering_element.css('display','inline-block'); |
|
360 |
} |
|
292 | 361 |
}); |
293 | 362 |
$cancel.appendTo($buttons); |
294 | 363 |
if (level == 1 && settings.settings.required && $('option', $triggering_element).length == 1) { |
... | ... | |
307 | 376 |
// Create a term object. |
308 | 377 |
var term = { |
309 | 378 |
vid: settings.vid, |
310 |
parent: $triggering_element.prev('select').val() || 0,
|
|
379 |
parent: (level === 1) ? 0 : ($triggering_element.prevAll('.shs-select').val() || 0),
|
|
311 | 380 |
name: termName |
312 | 381 |
}; |
313 | 382 |
if (termName.length > 0) { |
314 |
termAddNew($triggering_element, $container, term, base_id, level); |
|
383 |
termAddNew($triggering_element, $container, term, base_id, level, settings);
|
|
315 | 384 |
} |
316 | 385 |
else { |
317 | 386 |
// Remove container. |
387 |
$container.prev('label').remove(); |
|
318 | 388 |
$container.remove(); |
319 | 389 |
// Reset value of triggering element. |
320 | 390 |
$triggering_element.val(0); |
321 | 391 |
// Display triggering element. |
322 |
$triggering_element.fadeIn(); |
|
323 |
$triggering_element.css('display','inline-block');; |
|
392 |
$triggering_element.fadeIn(settings.display.animationSpeed);
|
|
393 |
$triggering_element.css('display', 'inline-block');;
|
|
324 | 394 |
} |
325 | 395 |
}); |
326 | 396 |
$save.appendTo($buttons); |
327 | 397 |
} |
328 |
else if ($triggering_element.val() != 0) { |
|
398 |
else if ($triggering_element.val() != 0 && $triggering_element.val() != settings.any_value) {
|
|
329 | 399 |
level++; |
400 |
$label = shsLabelCreate(base_id, settings, level); |
|
401 |
if ($label !== false) { |
|
402 |
$label.appendTo($triggering_element.parent()); |
|
403 |
} |
|
330 | 404 |
$element_new = shsElementCreate(base_id, settings, level); |
331 | 405 |
$element_new.appendTo($triggering_element.parent()); |
332 | 406 |
// Retrieve list of items for the new element. |
... | ... | |
334 | 408 |
} |
335 | 409 |
|
336 | 410 |
// Set value of original field. |
337 |
updateFieldValue($triggering_element, base_id, level, settings.multiple);
|
|
411 |
updateFieldValue($triggering_element, base_id, level, settings); |
|
338 | 412 |
} |
339 | 413 |
|
340 | 414 |
/** |
... | ... | |
352 | 426 |
*/ |
353 | 427 |
shsElementCreate = function(base_id, settings, level) { |
354 | 428 |
// Create element and initially hide it. |
429 |
$element = $('<select>') |
|
430 |
.attr('id', base_id + '-select-' + level) |
|
431 |
.addClass('shs-select') |
|
432 |
// Add core class to apply default styles to the element. |
|
433 |
.addClass('form-select') |
|
434 |
.addClass('shs-select-level-' + level) |
|
435 |
.bind('change', function() { |
|
436 |
updateElements($(this), base_id, settings, level); |
|
437 |
}) |
|
438 |
.hide(); |
|
355 | 439 |
if (settings.multiple) { |
356 |
$element = $('<select>') |
|
357 |
.attr('id', base_id + '-select-' + level) |
|
358 |
.attr('multiple', 'multiple') |
|
359 |
.addClass('shs-select') |
|
360 |
// Add core class to apply default styles to the element. |
|
361 |
.addClass('form-select') |
|
362 |
.addClass('shs-select-level-' + level) |
|
363 |
.bind('change', function() { |
|
364 |
updateElements($(this), base_id, settings, level); |
|
365 |
}) |
|
366 |
.hide(); |
|
440 |
$element.attr('multiple', 'multiple') |
|
367 | 441 |
} |
368 |
else { |
|
369 |
$element = $('<select>') |
|
370 |
.attr('id', base_id + '-select-' + level) |
|
371 |
.addClass('shs-select') |
|
372 |
// Add core class to apply default styles to the element. |
|
373 |
.addClass('form-select') |
|
374 |
.addClass('shs-select-level-' + level) |
|
375 |
.bind('change', function() { |
|
376 |
updateElements($(this), base_id, settings, level); |
|
377 |
}) |
|
378 |
.hide(); |
|
442 |
if (settings.settings.hasOwnProperty('required') && settings.settings.required) { |
|
443 |
$element.addClass('required'); |
|
379 | 444 |
} |
380 | 445 |
// Return the new element. |
381 | 446 |
return $element; |
382 | 447 |
} |
383 | 448 |
|
449 |
/** |
|
450 |
* Create label for dropdown in hierarchy. |
|
451 |
* |
|
452 |
* @param base_id |
|
453 |
* ID of original field which is rewritten as "taxonomy_shs". |
|
454 |
* @param settings |
|
455 |
* Field settings. |
|
456 |
* @param level |
|
457 |
* Current level in hierarchy. |
|
458 |
* |
|
459 |
* @return |
|
460 |
* The new <label> element or false if no label should be created. |
|
461 |
*/ |
|
462 |
shsLabelCreate = function(base_id, settings, level) { |
|
463 |
var labelKey = level - 1; |
|
464 |
if (!settings.hasOwnProperty('labels')) { |
|
465 |
return false; |
|
466 |
} |
|
467 |
if (!settings.labels.hasOwnProperty(labelKey) || settings.labels[labelKey] === false) { |
|
468 |
return false; |
|
469 |
} |
|
470 |
// Create element. |
|
471 |
$element = $('<label>') |
|
472 |
.attr('for', base_id + '-select-' + level) |
|
473 |
.addClass('element-invisible') |
|
474 |
.html(settings.labels[labelKey]); |
|
475 |
// Return the new element. |
|
476 |
return $element; |
|
477 |
} |
|
478 |
|
|
384 | 479 |
/** |
385 | 480 |
* Update value of original (hidden) field. |
386 | 481 |
* |
... | ... | |
390 | 485 |
* ID of original field which is rewritten as "taxonomy_shs". |
391 | 486 |
* @param level |
392 | 487 |
* Current level in hierarchy. |
488 |
* @param settings |
|
489 |
* Field settings. |
|
393 | 490 |
*/ |
394 |
updateFieldValue = function($triggering_element, base_id, level, multiple) {
|
|
491 |
updateFieldValue = function($triggering_element, base_id, level, settings) {
|
|
395 | 492 |
// Reset value of original field. |
396 | 493 |
$field_orig = $('#' + base_id); |
397 |
$field_orig.val(0);
|
|
494 |
$field_orig.val(settings.any_value);
|
|
398 | 495 |
// Set original field value. |
399 |
if ($triggering_element.val() == 0 || $triggering_element.val() == '_add_new_') {
|
|
400 |
if (level > 1) {
|
|
496 |
if ($triggering_element.val() === settings.any_value || $triggering_element.val() == '_add_new_') {
|
|
497 |
if ($triggering_element.prev('select').length) {
|
|
401 | 498 |
// Use value from parent level. |
402 | 499 |
$field_orig.val($triggering_element.prev('select').val()); |
403 | 500 |
} |
404 | 501 |
} |
405 | 502 |
else { |
406 | 503 |
var new_val = $triggering_element.val(); |
407 |
if (level > 1 && multiple) { |
|
504 |
if (level > 1 && settings.multiple) {
|
|
408 | 505 |
var new_value = ''; |
409 | 506 |
for (i = 0; i < level - 1; i++) { |
410 | 507 |
var prev_value = $('.shs-select:eq(' + i + ')').val(); |
... | ... | |
422 | 519 |
$field_orig.val(new_val.join(',')); |
423 | 520 |
} |
424 | 521 |
else { |
425 |
$field_orig.val(new_val); |
|
522 |
if ($field_orig.children('option[value="' + new_val + '"]').length > 0) { |
|
523 |
// Value exists. |
|
524 |
$field_orig.val(new_val); |
|
525 |
} |
|
526 |
else { |
|
527 |
// We need to append the new option. |
|
528 |
if ($field_orig.prop) { |
|
529 |
var options = $field_orig.prop('options'); |
|
530 |
} |
|
531 |
else { |
|
532 |
var options = $field_orig.attr('options'); |
|
533 |
} |
|
534 |
options[options.length] = new Option(new_val, new_val); |
|
535 |
$field_orig.val(new_val); |
|
536 |
} |
|
426 | 537 |
} |
427 | 538 |
} |
539 |
// Notify listeners about the change in the original select. |
|
540 |
$field_orig.trigger({ |
|
541 |
type: 'change', |
|
542 |
shs: { |
|
543 |
triggeringElement: $triggering_element, |
|
544 |
level: level, |
|
545 |
settings: settings, |
|
546 |
value: $triggering_element.val() |
|
547 |
} |
|
548 |
}); |
|
428 | 549 |
} |
429 | 550 |
|
430 | 551 |
/** |
... | ... | |
433 | 554 |
* @see http://drupal.org/project/chosen |
434 | 555 |
*/ |
435 | 556 |
elementConvertToChosen = function($element, settings) { |
436 |
if (Drupal.settings.chosen) { |
|
437 |
var minWidth = Drupal.settings.chosen.minimum_width; |
|
438 |
// Define options for chosen. |
|
439 |
var options = {}; |
|
440 |
options.search_contains = Drupal.settings.chosen.search_contains; |
|
441 |
options.placeholder_text_multiple = Drupal.settings.chosen.placeholder_text_multiple; |
|
442 |
options.placeholder_text_single = Drupal.settings.chosen.placeholder_text_single; |
|
443 |
options.no_results_text = Drupal.settings.chosen.no_results_text; |
|
444 |
|
|
445 |
// Get element selector from settings (and remove "visible" option since |
|
446 |
// our select element is hidden by default). |
|
447 |
var selector = Drupal.settings.chosen.selector.replace(/:visible/, ''); |
|
448 |
|
|
449 |
if ((settings.settings.use_chosen == 'always') || ((settings.settings.use_chosen == 'chosen') && ($element.is(selector) && $element.find('option').size() >= Drupal.settings.chosen.minimum))) { |
|
450 |
$element.css({ |
|
451 |
width : ($element.width() < minWidth) ? minWidth : $element.width() |
|
452 |
}).chosen(options); |
|
453 |
return true; |
|
454 |
} |
|
557 |
// Returns false if chosen is not available or its settings are undefined. |
|
558 |
if ($.fn.chosen === void 0 || !Drupal.settings.hasOwnProperty('chosen') || Drupal.settings.chosen === void 0) { |
|
559 |
return false; |
|
560 |
} |
|
561 |
|
|
562 |
var name = $element.attr('name'); |
|
563 |
settings.chosen = settings.chosen || Drupal.settings.chosen; |
|
564 |
var minWidth = settings.chosen.minimum_width; |
|
565 |
var multiple = Drupal.settings.chosen.multiple; |
|
566 |
var maxSelectedOptions = Drupal.settings.chosen.max_selected_options; |
|
567 |
|
|
568 |
// Define options. |
|
569 |
var options = { |
|
570 |
inherit_select_classes: true |
|
571 |
}; |
|
572 |
|
|
573 |
var minimum = multiple && multiple[name] ? settings.chosen.minimum_multiple : settings.chosen.minimum_single; |
|
574 |
|
|
575 |
if (maxSelectedOptions && maxSelectedOptions[name]) { |
|
576 |
options.max_selected_options = maxSelectedOptions[name]; |
|
455 | 577 |
} |
578 |
|
|
579 |
// Merges the user defined settings for chosen. |
|
580 |
options = $.extend(options, settings.chosen); |
|
581 |
|
|
582 |
// Get element selector from settings (and remove "visible" option since |
|
583 |
// our select element is hidden by default). |
|
584 |
var selector = settings.chosen.selector.replace(/:visible/, ''); |
|
585 |
if ((settings.settings.use_chosen === 'always') || ((settings.settings.use_chosen === 'chosen') && $element.is(selector) && ($element.find('option').size() >= minimum || minimum === 'Always Apply'))) { |
|
586 |
options = $.extend(options, { |
|
587 |
width: (($element.width() < minWidth) ? minWidth : $element.width()) + 'px' |
|
588 |
}); |
|
589 |
|
|
590 |
// Apply chosen to the element. |
|
591 |
return $element.chosen(options); |
|
592 |
} |
|
593 |
else if ((settings.settings.use_chosen === 'never') && (!$element.hasClass('chosen-disable'))) { |
|
594 |
// Tell chosen to not process this element. |
|
595 |
$element.addClass('chosen-disable'); |
|
596 |
} |
|
597 |
|
|
456 | 598 |
return false; |
457 | 599 |
} |
458 | 600 |
|
459 |
})(jQuery); |
|
601 |
})(jQuery, Drupal); |
drupal7/sites/all/modules/shs/modules/shs_node_count/shs_node_count.info | ||
---|---|---|
1 |
name = Simple hierarchical select: node count |
|
2 |
core = 7.x |
|
3 |
description = Extends 'Simple hierarchical select' with "node count" functionality. |
|
4 |
dependencies[] = shs |
|
5 |
|
|
6 |
; Information added by Drupal.org packaging script on 2018-03-06 |
|
7 |
version = "7.x-1.7" |
|
8 |
core = "7.x" |
|
9 |
project = "shs" |
|
10 |
datestamp = "1520313188" |
|
11 |
|
drupal7/sites/all/modules/shs/modules/shs_node_count/shs_node_count.install | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
/** |
|
4 |
* @file |
|
5 |
* Installation tasks for "SHS node count". |
|
6 |
*/ |
|
7 |
|
|
8 |
/** |
|
9 |
* Implements hook_uninstall(). |
|
10 |
*/ |
|
11 |
function shs_node_count_uninstall() { |
|
12 |
variable_del('shs_node_count_format'); |
|
13 |
} |
drupal7/sites/all/modules/shs/modules/shs_node_count/shs_node_count.module | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
/** |
|
4 |
* @file |
|
5 |
* Node count functionality for Simple hierarchical select. |
|
6 |
*/ |
|
7 |
|
|
8 |
/** |
|
9 |
* Implements hook_field_widget_info_alter(). |
|
10 |
*/ |
|
11 |
function shs_node_count_field_widget_info_alter(&$info) { |
|
12 |
if (empty($info['taxonomy_shs'])) { |
|
13 |
return; |
|
14 |
} |
|
15 |
// Add "a"node_count" setting to a shs widgets. |
|
16 |
$info['taxonomy_shs']['settings']['shs'] += array( |
|
17 |
'node_count' => FALSE, |
|
18 |
); |
|
19 |
} |
|
20 |
|
|
21 |
/** |
|
22 |
* Implements hook_form_FORM_ID_alter(). |
|
23 |
*/ |
|
24 |
function shs_node_count_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) { |
|
25 |
if (empty($form['instance']['widget']['settings']['shs'])) { |
|
26 |
return; |
|
27 |
} |
|
28 |
$settings_form = &$form['instance']['widget']['settings']['shs']; |
|
29 |
$settings = &$form['#instance']['widget']['settings']['shs']; |
|
30 |
|
|
31 |
$settings_form['node_count'] = array( |
|
32 |
'#type' => 'checkbox', |
|
33 |
'#title' => t('Display number of nodes'), |
|
34 |
'#description' => t('Display the number of nodes associated with the term.'), |
|
35 |
'#default_value' => empty($settings['node_count']) ? FALSE : $settings['node_count'], |
|
36 |
'#weight' => -1, |
|
37 |
); |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* Implements hook_shs_term_get_children_alter(). |
|
42 |
*/ |
|
43 |
function shs_node_count_shs_term_get_children_alter(&$terms, &$alter_options) { |
|
44 |
if (empty($alter_options['settings']['node_count']) || empty($alter_options['settings']['language']) || !isset($alter_options['parent'])) { |
|
45 |
// Nothing to do here. |
|
46 |
return; |
|
47 |
} |
|
48 |
$langcode = $alter_options['settings']['language']->language; |
|
49 |
$term = (object) array( |
|
50 |
'vid' => $alter_options['vid'], |
|
51 |
'tid' => 0, |
|
52 |
); |
|
53 |
$format = variable_get('shs_node_count_format', '%s (%d)'); |
|
54 |
foreach ($terms as &$item) { |
|
55 |
array_walk($item[$langcode][$alter_options['parent']], function (&$name, $key) use ($term, $format) { |
|
56 |
$term->tid = $key; |
|
57 |
$count = shs_node_count_term_get_node_count($term, TRUE); |
|
58 |
$name = sprintf($format, $name, $count); |
|
59 |
}); |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* Helper function to count number of nodes associated to a term. |
|
65 |
* |
|
66 |
* @param object $term |
|
67 |
* The term object. |
|
68 |
* @param boolean $count_children |
|
69 |
* If set to TRUE, nodes in child terms are counted also. |
|
70 |
* |
|
71 |
* @return int |
|
72 |
* Number of nodes within the term. |
|
73 |
*/ |
|
74 |
function shs_node_count_term_get_node_count($term, $count_children = FALSE) { |
|
75 |
$num_nodes = &drupal_static(__FUNCTION__, array()); |
|
76 |
|
|
77 |
// Maybe this needs some more caching and value-updates on node_save()/ |
|
78 |
// _update()/delete(). |
|
79 |
if (empty($num_nodes["{$term->tid}:{$count_children}"])) { |
|
80 |
$index_table = 'taxonomy_index'; |
|
81 |
if (module_exists('taxonomy_entity_index')) { |
|
82 |
$index_table = 'taxonomy_entity_index'; |
|
83 |
} |
|
84 |
|
|
85 |
// Count nodes associated to this term. |
|
86 |
$num_nodes["{$term->tid}:{$count_children}"] = db_select($index_table, 'ti') |
|
87 |
->fields('ti') |
|
88 |
->condition('tid', $term->tid) |
|
89 |
->execute() |
|
90 |
->rowCount(); |
|
91 |
|
|
92 |
if ($count_children) { |
|
93 |
$tids = array(); |
|
94 |
$tree = taxonomy_get_tree($term->vid, $term->tid); |
|
95 |
foreach ($tree as $child_term) { |
|
96 |
$tids[] = $child_term->tid; |
|
97 |
} |
|
98 |
if (count($tids)) { |
|
99 |
$num_nodes["{$term->tid}:{$count_children}"] += db_select($index_table, 'ti') |
Formats disponibles : Unified diff
Weekly update of contrib modules