Révision 136a805a
Ajouté par Assos Assos il y a plus de 7 ans
drupal7/sites/all/modules/ctools/plugins/arguments/term.inc | ||
---|---|---|
18 | 18 |
'context' => 'ctools_term_context', |
19 | 19 |
'default' => array('input_form' => 'tid', 'breadcrumb' => TRUE, 'transform' => FALSE), |
20 | 20 |
'settings form' => 'ctools_term_settings_form', |
21 |
'settings form validate' => 'ctools_term_settings_form_validate', |
|
21 | 22 |
'placeholder form' => 'ctools_term_ctools_argument_placeholder', |
22 | 23 |
'breadcrumb' => 'ctools_term_breadcrumb', |
23 | 24 |
); |
... | ... | |
31 | 32 |
return ctools_context_create_empty('entity:taxonomy_term'); |
32 | 33 |
} |
33 | 34 |
|
35 |
if (isset($conf['vocabularies'])) { |
|
36 |
$vocabularies = $conf['vocabularies']; |
|
37 |
} |
|
38 |
else { |
|
39 |
$vids = isset($conf['vids']) ? $conf['vids'] : array(); |
|
40 |
|
|
41 |
// Convert legacy use of vids to machine names. |
|
42 |
$vocabularies = _ctools_term_vocabulary_machine_name_convert($vids); |
|
43 |
} |
|
44 |
|
|
34 | 45 |
if (is_object($arg)) { |
35 | 46 |
$term = $arg; |
36 | 47 |
} |
... | ... | |
50 | 61 |
} |
51 | 62 |
|
52 | 63 |
$terms = taxonomy_get_term_by_name($arg); |
53 |
|
|
54 |
$conf['vids'] = is_array($conf['vids']) ? array_filter($conf['vids']) : NULL; |
|
55 |
if ((count($terms) > 1) && isset($conf['vids'])) { |
|
64 |
// If only one term is found, fall through to vocabulary check below. |
|
65 |
if ((count($terms) > 1) && $vocabularies) { |
|
56 | 66 |
foreach ($terms as $potential) { |
57 |
foreach ($conf['vids'] as $vid => $active) {
|
|
58 |
if ($active && $potential->vid == $vid) {
|
|
67 |
foreach ($vocabularies as $machine_name) {
|
|
68 |
if ($potential->vocabulary_machine_name == $machine_name) {
|
|
59 | 69 |
$term = $potential; |
60 | 70 |
// break out of the foreaches AND the case |
61 | 71 |
break 3; |
... | ... | |
72 | 82 |
} |
73 | 83 |
} |
74 | 84 |
|
75 |
if (!empty($conf['vids']) && array_filter($conf['vids']) && empty($conf['vids'][$term->vid])) {
|
|
85 |
if ($vocabularies && !isset($vocabularies[$term->vocabulary_machine_name])) {
|
|
76 | 86 |
return NULL; |
77 | 87 |
} |
78 | 88 |
|
... | ... | |
98 | 108 |
$vocabularies = taxonomy_get_vocabularies(); |
99 | 109 |
$options = array(); |
100 | 110 |
foreach ($vocabularies as $vid => $vocab) { |
101 |
$options[$vid] = $vocab->name; |
|
111 |
$options[$vocab->machine_name] = $vocab->name; |
|
112 |
} |
|
113 |
|
|
114 |
// Fallback on legacy 'vids', when no vocabularies are available. |
|
115 |
if (empty($conf['vocabularies']) && !empty($conf['vids'])) { |
|
116 |
$conf['vocabularies'] = _ctools_term_vocabulary_machine_name_convert(array_filter($conf['vids'])); |
|
117 |
unset($conf['vids']); |
|
102 | 118 |
} |
103 |
$form['settings']['vids'] = array( |
|
119 |
|
|
120 |
$form['settings']['vocabularies'] = array( |
|
104 | 121 |
'#title' => t('Limit to these vocabularies'), |
105 | 122 |
'#type' => 'checkboxes', |
106 | 123 |
'#options' => $options, |
107 |
'#default_value' => !empty($conf['vids']) ? $conf['vids'] : array(),
|
|
124 |
'#default_value' => !empty($conf['vocabularies']) ? $conf['vocabularies'] : array(),
|
|
108 | 125 |
'#description' => t('If no vocabularies are checked, terms from all vocabularies will be accepted.'), |
109 | 126 |
); |
110 | 127 |
|
... | ... | |
123 | 140 |
// return $form; |
124 | 141 |
} |
125 | 142 |
|
143 |
function ctools_term_settings_form_validate (&$form, &$form_state) { |
|
144 |
// Filter the selected vocabularies to avoid storing redundant data. |
|
145 |
$vocabularies = array_filter($form_state['values']['settings']['vocabularies']); |
|
146 |
form_set_value($form['settings']['vocabularies'], $vocabularies, $form_state); |
|
147 |
} |
|
148 |
|
|
126 | 149 |
/** |
127 | 150 |
* Form fragment to get an argument to convert a placeholder for preview. |
128 | 151 |
*/ |
... | ... | |
161 | 184 |
$breadcrumb = array_merge(drupal_get_breadcrumb(), array_reverse($breadcrumb)); |
162 | 185 |
drupal_set_breadcrumb($breadcrumb); |
163 | 186 |
} |
187 |
|
|
188 |
/** |
|
189 |
* Helper function to convert convert legacy vocabulary ids into machine names. |
|
190 |
* |
|
191 |
* @param array $vids |
|
192 |
* Array of either vids. |
|
193 |
* @return array |
|
194 |
* A keyed array of machine names. |
|
195 |
*/ |
|
196 |
function _ctools_term_vocabulary_machine_name_convert($vids) { |
|
197 |
$vocabularies = taxonomy_vocabulary_load_multiple($vids); |
|
198 |
$return = array(); |
|
199 |
foreach($vocabularies as $vocabulary) { |
|
200 |
$return[$vocabulary->machine_name] = $vocabulary->machine_name; |
|
201 |
} |
|
202 |
return $return; |
|
203 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules