[#1096548] by dww: Remember the vid when converting D5 taxonomy term fields.
[project/views.git] / modules / taxonomy.views_convert.inc
CommitLineData
5d01fcde 1<?php
5d01fcde
EM
2
3/**
4 * @file
5 * Field conversion for fields handled by this module.
6 */
7
8/**
9 * Implementation of hook_views_convert().
10 *
11 * Intervene to convert field values from the Views 1 format to the
12 * Views 2 format. Intervene only if $view->add_item() won't produce
13 * the right results, usually needed to set field options or values.
14 */
15function taxonomy_views_convert($display, $type, &$view, $field, $id = NULL) {
473e3346
EM
16 switch ($type) {
17 case 'field':
b7e53255
DW
18 $matches = array();
19 if (preg_match('/term_node(_(\d+))?/', $field['tablename'], $matches)) {
5d01fcde
EM
20 switch ($field['field']) {
21 case 'name':
22 $item = $view->get_item($display, 'field', $id);
f9846dd4
DW
23 $item['table'] = 'term_node';
24 $item['field'] = 'tid';
5d01fcde
EM
25 if ($field['options'] != 'nolink') {
26 $item['link_to_taxonomy'] = TRUE;
27 }
28 if (!empty($field['vocabulary'])) {
29 $item['limit'] = TRUE;
30 $item['vids'] = array($field['vocabulary']);
31 }
b7e53255
DW
32 // The vocabulary ID might be embedded in the table name.
33 elseif (!empty($matches[2])) {
34 $item['limit'] = TRUE;
35 $item['vids'] = array($matches[2]);
36 }
5d01fcde
EM
37 $view->set_item($display, 'field', $id, $item);
38 break;
39 }
473e3346 40 }
11ffffec
EM
41 elseif ($field['tablename'] == 'term_data') {
42 switch ($field['field']) {
43 case 'name':
44 if ($field['field'] == 'views_handler_field_tid_link') {
45 $view->set_item_option($display, 'field', $id, 'link_to_taxonomy', TRUE);
46 }
47 break;
48 }
49 }
473e3346
EM
50 break;
51 case 'filter':
52 if ($field['tablename'] == 'term_node' || !strncmp($field['tablename'], 'term_node_', 10)) {
53 switch ($field['field']) {
54 case 'tid':
11ffffec 55 $operators = array('AND' => 'and', 'OR' => 'or', 'NOR' => 'not');
473e3346 56 $item = $view->get_item($display, 'filter', $id);
473e3346 57 if ($vid = (integer) substr($field['tablename'], 10)) {
11ffffec 58 $item['table'] = 'term_node';
473e3346
EM
59 $item['vid'] = $vid;
60 }
61 else {
62 $item['limit'] = FALSE;
63 }
11ffffec 64 $item['operator'] = $operators[$field['operator']];
473e3346 65 $item['type'] = 'select';
473e3346
EM
66 $view->set_item($display, 'filter', $id, $item);
67 break;
68 }
69 }
11ffffec
EM
70 elseif ($field['tablename'] == 'term_data') {
71 switch ($field['field']) {
72 case 'vid':
73 $operators = array('AND' => 'in', 'OR' => 'in', 'NOR' => 'not in');
74 $view->set_item_option($display, 'filter', $id, 'operator', $operators[$field['operator']]);
11ffffec
EM
75 break;
76 }
77 }
473e3346
EM
78 break;
79 case 'argument':
11ffffec 80 $options = $field['argoptions'];
473e3346
EM
81 switch ($field['type']) {
82 case 'taxid':
473e3346
EM
83 if (!empty($field['options'])) {
84 $options['depth'] = $field['options'];
85 }
86 $options['break_phrase'] = TRUE;
11ffffec 87 $view->add_item($display, 'argument', 'node', 'term_node_tid_depth', $options, $field['id']);
473e3346
EM
88 break;
89 case 'taxletter':
473e3346
EM
90 if (!empty($field['options'])) {
91 $options['glossary'] = TRUE;
92 $options['limit'] = $field['options'];
93 }
11ffffec 94 $view->add_item($display, 'argument', 'term_data', 'name', $options, $field['id']);
473e3346
EM
95 break;
96 case 'vocid':
11ffffec 97 $view->add_item($display, 'argument', 'vocabulary', 'vid', $options, $field['id']);
473e3346
EM
98 break;
99 }
100 break;
5d01fcde
EM
101 }
102}