/[drupal]/contributions/modules/views/modules/taxonomy.views.inc
ViewVC logotype

Contents of /contributions/modules/views/modules/taxonomy.views.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.57 - (show annotations) (download) (as text)
Wed Jul 1 06:13:49 2009 UTC (4 months, 3 weeks ago) by merlinofchaos
Branch: MAIN
CVS Tags: DRUPAL-6--2-7, HEAD
Branch point for: DRUPAL-6--2, DRUPAL-7--3
Changes since 1.56: +8 -3 lines
File MIME type: text/x-php
Can now directly add a taxonomy term relationship to nodes, allowing more control by vocabulary.
1 <?php
2 // $Id: taxonomy.views.inc,v 1.56 2009/06/30 18:01:05 merlinofchaos Exp $
3 /**
4 * @file
5 *
6 * Provide views data and handlers for taxonomy.module
7 */
8
9 /**
10 * @defgroup views_taxonomy_module taxonomy.module handlers
11 *
12 * @{
13 */
14
15 /**
16 * Implementation of hook_views_data()
17 */
18 function taxonomy_views_data() {
19 $data = array();
20
21 // ----------------------------------------------------------------------
22 // vocabulary table
23
24 $data['vocabulary']['table']['group'] = t('Taxonomy');
25
26 $data['vocabulary']['table']['join'] = array(
27 // vocabulary links to term_data directly via vid.
28 'term_data' => array(
29 'left_field' => 'vid',
30 'field' => 'vid',
31 ),
32 // vocabulary links to node through term_data via vid
33 'node' => array(
34 'left_table' => 'term_data',
35 'left_field' => 'vid',
36 'field' => 'vid',
37 ),
38 // vocabulary links to node_revision via term_data
39 'node_revision' => array(
40 'left_table' => 'term_data',
41 'left_field' => 'vid',
42 'field' => 'vid',
43 ),
44 );
45
46 // vocabulary name
47 $data['vocabulary']['name'] = array(
48 'title' => t('Vocabulary name'), // The item it appears as on the UI,
49 'field' => array(
50 'help' => t('Name of the vocabulary a term is a member of. This will be the vocabulary that whichever term the "Taxonomy: Term" field is; and can similarly cause duplicates.'),
51 'handler' => 'views_handler_field',
52 'click sortable' => TRUE,
53 ),
54 );
55 $data['vocabulary']['vid'] = array(
56 'title' => t('Vocabulary ID'), // The item it appears as on the UI,
57 'help' => t('The taxonomy vocabulary ID'),
58 'argument' => array(
59 'handler' => 'views_handler_argument_vocabulary_vid',
60 'name field' => 'name',
61 ),
62 );
63
64 // ----------------------------------------------------------------------
65 // term_data table
66
67 $data['term_data']['table']['group'] = t('Taxonomy');
68 $data['term_data']['table']['base'] = array(
69 'field' => 'tid',
70 'title' => t('Term'),
71 'help' => t('Taxonomy terms are attached to nodes.'),
72 );
73
74
75 // The term data table
76 $data['term_data']['table']['join'] = array(
77 'node' => array(
78 'left_table' => 'term_node',
79 'left_field' => 'tid',
80 'field' => 'tid',
81 ),
82 'node_revision' => array(
83 'left_table' => 'term_node',
84 'left_field' => 'tid',
85 'field' => 'tid',
86 ),
87 // This is provided for many_to_one argument
88 'term_node' => array(
89 'field' => 'tid',
90 'left_field' => 'tid',
91 ),
92 );
93
94 // tid field
95 $data['term_data']['tid'] = array(
96 'title' => t('Term ID'),
97 'help' => t('The taxonomy term ID'),
98 'field' => array(
99 'handler' => 'views_handler_field_numeric',
100 'click sortable' => TRUE,
101 ),
102 'sort' => array(
103 'handler' => 'views_handler_sort',
104 ),
105 'argument' => array(
106 'handler' => 'views_handler_argument_numeric',
107 'skip base' => array('node', 'node_revision'),
108 ),
109 'filter' => array(
110 'handler' => 'views_handler_filter_term_node_tid',
111 'hierarchy table' => 'term_hierarchy',
112 'numeric' => TRUE,
113 'skip base' => array('node', 'node_revision'),
114 ),
115 );
116
117 // Term name field
118 $data['term_data']['name'] = array(
119 'title' => t('Term'),
120 'help' => t('Taxonomy terms. Note that using this can cause duplicate nodes to appear in views; you must add filters to reduce the result set.'),
121 'field' => array(
122 'handler' => 'views_handler_field_taxonomy',
123 'click sortable' => TRUE,
124 ),
125 'sort' => array(
126 'handler' => 'views_handler_sort',
127 ),
128 'argument' => array(
129 'handler' => 'views_handler_argument_string',
130 'help' => t('Taxonomy term name.'),
131 'many to one' => TRUE,
132 'empty field name' => t('Uncategorized'),
133 ),
134 );
135
136 // taxonomy weight
137 $data['term_data']['weight'] = array(
138 'title' => t('Weight'),
139 'help' => t('The term weight field'),
140 'field' => array(
141 'handler' => 'views_handler_field',
142 'click sortable' => TRUE,
143 ),
144 'sort' => array(
145 'handler' => 'views_handler_sort',
146 ),
147 );
148
149 // Term description
150 $data['term_data']['description'] = array(
151 'title' => t('Term description'), // The item it appears as on the UI,
152 'help' => t('The description associated with a taxonomy term.'),
153 'field' => array(
154 'field' => 'description', // the real field
155 'group' => t('Taxonomy'), // The group it appears in on the UI,
156 'handler' => 'views_handler_field_markup',
157 'format' => FILTER_FORMAT_DEFAULT,
158 ),
159 );
160
161 // Term vocabulary
162 $data['term_data']['vid'] = array(
163 'title' => t('Vocabulary'),
164 'help' => t('Filter the results of "Taxonomy: Term" to a particular vocabulary.'),
165 'filter' => array(
166 'handler' => 'views_handler_filter_vocabulary_vid',
167 ),
168 );
169
170 // ----------------------------------------------------------------------
171 // term_node table
172
173 $data['term_node']['table']['group'] = t('Taxonomy');
174
175 $data['term_node']['table']['join'] = array(
176 'term_data' => array(
177 // links directly to term_data via tid
178 'left_field' => 'tid',
179 'field' => 'tid',
180 ),
181 'node' => array(
182 // links directly to node via vid
183 'left_field' => 'vid',
184 'field' => 'vid',
185 ),
186 'node_revisions' => array(
187 // links directly to node_revisions via vid
188 'left_field' => 'vid',
189 'field' => 'vid',
190 ),
191 'term_hierarchy' => array(
192 'left_field' => 'tid',
193 'field' => 'tid',
194 ),
195 );
196
197 // tid field
198 $data['term_node']['tid'] = array(
199 'title' => t('Term ID'),
200 'help' => t('The taxonomy term ID'),
201 'field' => array(
202 'title' => t('All terms'),
203 'help' => t('Display all taxonomy terms associated with a node from specified vocabularies.'),
204 'handler' => 'views_handler_field_term_node_tid',
205 'skip base' => 'term_data',
206 ),
207 'argument' => array(
208 'handler' => 'views_handler_argument_term_node_tid',
209 'name table' => 'term_data',
210 'name field' => 'name',
211 'empty field name' => t('Uncategorized'),
212 'numeric' => TRUE,
213 'skip base' => 'term_data',
214 ),
215 'filter' => array(
216 'title' => t('Term'),
217 'handler' => 'views_handler_filter_term_node_tid',
218 'hierarchy table' => 'term_hierarchy',
219 'numeric' => TRUE,
220 'skip base' => 'term_data',
221 'allow empty' => TRUE,
222 ),
223 );
224
225 // @todo: term_relation
226
227 // ----------------------------------------------------------------------
228 // term_hierarchy table
229
230 $data['term_hierarchy']['table']['group'] = t('Taxonomy');
231
232 $data['term_hierarchy']['table']['join'] = array(
233 'term_hierarchy' => array(
234 // links to self through left.parent = right.tid (going down in depth)
235 'left_field' => 'tid',
236 'field' => 'parent',
237 ),
238 'term_data' => array(
239 // links directly to term_data via tid
240 'left_field' => 'tid',
241 'field' => 'tid',
242 ),
243 'node' => array(
244 // links to node thorugh term_data
245 'left_table' => 'term_data',
246 'left_field' => 'tid',
247 'field' => 'tid',
248 ),
249 'node_revisions' => array(
250 // links to node_revisions thorugh term_data
251 'left_table' => 'term_data',
252 'left_field' => 'tid',
253 'field' => 'tid',
254 ),
255 );
256
257 $data['term_hierarchy']['parent'] = array(
258 'title' => t('Parent term'),
259 'help' => t('The parent term of the term. This can produce duplicate entries if you are using a vocabulary that allows multiple parents.'),
260 'relationship' => array(
261 'base' => 'term_data',
262 'field' => 'parent',
263 'label' => t('Parent'),
264 ),
265 'argument' => array(
266 'help' => t('The parent term of the term.'),
267 'handler' => 'views_handler_argument_numeric',
268 ),
269 );
270
271 // ----------------------------------------------------------------------
272 // term_synonym table
273
274 $data['term_synonym']['table']['group'] = t('Taxonomy');
275
276 $data['term_synonym']['table']['join'] = array(
277 'term_data' => array(
278 // links directly to term_data via tid
279 'left_field' => 'tid',
280 'field' => 'tid',
281 ),
282 'node' => array(
283 'left_table' => 'term_node',
284 'left_field' => 'tid',
285 'field' => 'tid',
286 ),
287 'node_revisions' => array(
288 'left_table' => 'term_node',
289 'left_field' => 'tid',
290 'field' => 'tid',
291 ),
292 );
293
294 $data['term_synonym']['name'] = array(
295 'title' => t('Term synonym'),
296 'help' => t('Term synonyms may be used to find terms by alternate names.'),
297 'argument' => array(
298 'handler' => 'views_handler_argument_string',
299 'many to one' => TRUE,
300 'empty field name' => t('Uncategorized'),
301 ),
302 );
303 return $data;
304 }
305
306 /**
307 * Implementation of hook_views_data_alter().
308 */
309 function taxonomy_views_data_alter(&$data) {
310 $data['node']['term_node_tid'] = array(
311 'group' => t('Taxonomy'),
312 'title' => t('Related terms'),
313 'help' => t('Relate nodes to taxonomy terms, specifiying which vocabulary or vocabularies to use. This relationship will cause duplicated records if there are multiple terms.'),
314 'relationship' => array(
315 'handler' => 'views_handler_relationship_node_term_data',
316 'label' => t('term'),
317 'base' => 'term_data',
318 ),
319 );
320
321 $data['node']['term_node_tid_depth'] = array(
322 'group' => t('Taxonomy'),
323 'title' => t('Term ID (with depth)'),
324 'help' => t('The depth filter is more complex, so provides fewer options.'),
325 'real field' => 'vid',
326 'argument' => array(
327 'handler' => 'views_handler_argument_term_node_tid_depth',
328 'accept depth modifier' => TRUE,
329 ),
330 'filter' => array(
331 'handler' => 'views_handler_filter_term_node_tid_depth',
332 ),
333 );
334
335 $data['node']['term_node_tid_depth_modifier'] = array(
336 'group' => t('Taxonomy'),
337 'title' => t('Term ID depth modifier'),
338 'help' => t('Allows the "depth" for Taxonomy: Term ID (with depth) to be modified via an additional argument.'),
339 'argument' => array(
340 'handler' => 'views_handler_argument_term_node_tid_depth_modifier',
341 ),
342 );
343 }
344
345 /**
346 * Implementation of hook_views_handlers() to register all of the basic handlers
347 * views uses.
348 */
349 function taxonomy_views_handlers() {
350 return array(
351 'info' => array(
352 'path' => drupal_get_path('module', 'views') . '/modules/taxonomy',
353 ),
354 'handlers' => array(
355 'views_handler_argument_term_node_tid_depth' => array(
356 'parent' => 'views_handler_argument',
357 ),
358 'views_handler_argument_term_node_tid_depth_modifier' => array(
359 'parent' => 'views_handler_argument',
360 ),
361 'views_handler_argument_taxonomy' => array(
362 'parent' => 'views_handler_argument',
363 ),
364 'views_handler_argument_vocabulary_vid' => array(
365 'parent' => 'views_handler_argument',
366 ),
367 'views_handler_argument_term_node_tid' => array(
368 'parent' => 'views_handler_argument_many_to_one',
369 ),
370 'views_handler_field_term_node_tid' => array(
371 'parent' => 'views_handler_field_prerender_list',
372 ),
373 'views_handler_field_taxonomy' => array(
374 'parent' => 'views_handler_field',
375 ),
376 'views_handler_filter_vocabulary_vid' => array(
377 'parent' => 'views_handler_filter_in_operator',
378 ),
379 'views_handler_filter_term_node_tid' => array(
380 'parent' => 'views_handler_filter_many_to_one',
381 ),
382 'views_handler_filter_term_node_tid_depth' => array(
383 'parent' => 'views_handler_filter_term_node_tid',
384 ),
385 'views_handler_relationship_node_term_data' => array(
386 'parent' => 'views_handler_relationship',
387 ),
388 ),
389 );
390 }
391
392 /**
393 * Implementation of hook_views_plugins
394 */
395 function taxonomy_views_plugins() {
396 return array(
397 'module' => 'views', // This just tells our themes are elsewhere.
398 'argument validator' => array(
399 'taxonomy_term' => array(
400 'title' => t('Taxonomy term'),
401 'handler' => 'views_plugin_argument_validate_taxonomy_term',
402 'path' => drupal_get_path('module', 'views') . '/modules/taxonomy',
403 ),
404 ),
405 );
406 }
407
408 /**
409 * Helper function to set a breadcrumb for taxonomy.
410 */
411 function views_taxonomy_set_breadcrumb(&$breadcrumb, &$argument) {
412 if (empty($argument->options['set_breadcrumb'])) {
413 return;
414 }
415
416 $args = $argument->view->args;
417 $parents = taxonomy_get_parents_all($argument->argument);
418 foreach (array_reverse($parents) as $parent) {
419 // Unfortunately parents includes the current argument. Skip.
420 if ($parent->tid == $argument->argument) {
421 continue;
422 }
423 $args[$argument->position] = $parent->tid;
424 $path = $argument->view->get_url($args);
425 $breadcrumb[$path] = check_plain($parent->name);
426 }
427 }
428
429 /**
430 * @}
431 */

  ViewVC Help
Powered by ViewVC 1.1.2