node.views_convert.inc

Field conversion for fields handled by this module.

File

modules/node.views_convert.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Field conversion for fields handled by this module.
  5. */
  6. /**
  7. * Implementation of hook_views_convert().
  8. *
  9. * Intervene to convert field values from the Views 1 format to the
  10. * Views 2 format. Intervene only if $view->add_item() won't produce
  11. * the right results, usually needed to set field options or values.
  12. */
  13. function node_views_convert($display, $type, &$view, $field, $id = NULL) {
  14. switch ($type) {
  15. case 'field':
  16. switch ($field['tablename']) {
  17. case 'node':
  18. switch ($field['field']) {
  19. case 'title':
  20. if ($field['options'] != 'no_link') {
  21. $view->set_item_option($display, 'field', $id, 'link_to_node', TRUE);
  22. }
  23. break;
  24. case 'created':
  25. case 'changed':
  26. $handlers = array(
  27. 'views_handler_field_date_small' => 'small',
  28. 'views_handler_field_date' => 'medium',
  29. 'views_handler_field_date_large' => 'large',
  30. 'views_handler_field_date_custom' => 'custom',
  31. 'views_handler_field_since' => 'time ago',
  32. );
  33. $view->set_item_option($display, 'field', $id, 'date_format', $handlers[$field['handler']]);
  34. if (!empty($field['options'])) {
  35. $view->set_item_option($display, 'field', $id, 'custom_date_format', $field['options']);
  36. }
  37. break;
  38. case 'body':
  39. $field['field'] = $field['handler'] == 'views_handler_field_teaser' ? 'teaser' : $field['field'];
  40. $view->set_item_option($display, 'field', $id, 'field', $field['field']);
  41. $view->set_item_option($display, 'field', $id, 'table', 'node_revisions');
  42. break;
  43. case 'link':
  44. case 'edit':
  45. case 'delete':
  46. case 'view':
  47. $field['field'] = $field['field'] == 'link' ? 'view_node' : "$field[field]_node";
  48. $view->set_item_option($display, 'field', $id, 'field', $field['field']);
  49. if (!empty($field['options'])) {
  50. $view->set_item_option($display, 'field', $id, 'text', $field['options']);
  51. }
  52. break;
  53. }
  54. break;
  55. }
  56. break;
  57. case 'filter':
  58. switch ($field['tablename']) {
  59. case 'node':
  60. switch ($field['field']) {
  61. case 'type':
  62. $operators = array('OR' => 'in', 'NOR' => 'not in');
  63. $view->set_item_option($display, 'filter', $id, 'operator', $operators[$field['operator']]);
  64. break;
  65. case 'anon':
  66. $item = $view->get_item($display, 'filter', $id);
  67. $item['value'] = array(0);
  68. $item['table'] = 'users';
  69. $item['field'] = 'uid';
  70. $view->set_item($display, 'filter', $id, $item);
  71. break;
  72. case 'currentuid':
  73. $operators = array('=' => TRUE, '!=' => FALSE);
  74. $item = $view->get_item($display, 'filter', $id);
  75. $item['value'] = $operators[$field['operator']];
  76. $item['table'] = 'users';
  77. $item['field'] = 'uid_current';
  78. $view->set_item($display, 'filter', $id, $item);
  79. break;
  80. case 'currentuidtouched':
  81. $view->set_item_option($display, 'filter', $id, 'value', '=');
  82. $view->set_item_option($display, 'filter', $id, 'field', 'uid_touch');
  83. break;
  84. case 'distinct':
  85. $view->display_handler->set_option('distinct', $field['operator'] == '=' && $field['value'] == 'distinct');
  86. $view->set_item($display, 'filter', $id, NULL);
  87. break;
  88. case 'title':
  89. $item = $view->get_item($display, 'filter', $id);
  90. $item['operator'] = $field['operator'];
  91. $item['case'] = FALSE;
  92. $view->set_item($display, 'filter', $id, $item);
  93. break;
  94. case 'created':
  95. case 'changed':
  96. $item = $view->get_item($display, 'filter', $id);
  97. $item['operator'] = $field['operator'];
  98. $item['value'] = array(
  99. 'type' => $field['value'] == 'now' ? 'offset' : 'date',
  100. 'value' => $field['value'],
  101. );
  102. if (!empty($field['options'])) {
  103. $item['value']['value'] = intval($field['options']) .' seconds';
  104. }
  105. $view->set_item($display, 'filter', $id, $item);
  106. break;
  107. case 'body':
  108. $item = $view->get_item($display, 'filter', $id);
  109. $item['operator'] = $field['operator'];
  110. $item['case'] = FALSE;
  111. $item['table'] = 'node_revisions';
  112. $view->set_item($display, 'filter', $id, $item);
  113. break;
  114. }
  115. break;
  116. case 'history':
  117. switch ($field['field']) {
  118. case 'timestamp':
  119. $view->set_item_option($display, 'filter', $id, 'table', 'history_user');
  120. break;
  121. }
  122. break;
  123. }
  124. break;
  125. case 'sort':
  126. switch ($field['tablename']) {
  127. case 'node':
  128. switch ($field['field']) {
  129. case 'created':
  130. case 'changed':
  131. $field['options'] = $field['options'] == 'normal' ? 'second' : $field['options'];
  132. $view->set_item_option($display, 'sort', $id, 'granularity', $field['options']);
  133. break;
  134. case 'random':
  135. $view->set_item_option($display, 'sort', $id, 'table', 'views');
  136. break;
  137. }
  138. break;
  139. }
  140. break;
  141. case 'argument':
  142. $options = $field['argoptions'];
  143. switch ($field['type']) {
  144. case 'nodetype':
  145. $view->add_item($display, 'argument', 'node', 'type', $options, $field['id']);
  146. break;
  147. case 'nodeletter':
  148. if (!empty($field['options'])) {
  149. $options['glossary'] = TRUE;
  150. $options['limit'] = $field['options'];
  151. }
  152. $options['case'] = 'upper';
  153. $view->add_item($display, 'argument', 'node', 'title', $options, $field['id']);
  154. break;
  155. case 'year':
  156. $view->add_item($display, 'argument', 'node', 'created_year', $options, $field['id']);
  157. break;
  158. case 'month':
  159. $view->add_item($display, 'argument', 'node', 'created_month', $options, $field['id']);
  160. break;
  161. case 'week':
  162. $view->add_item($display, 'argument', 'node', 'created_week', $options, $field['id']);
  163. break;
  164. case 'monthyear':
  165. $view->add_item($display, 'argument', 'node', 'created_year_month', $options, $field['id']);
  166. break;
  167. case 'fulldate':
  168. $view->add_item($display, 'argument', 'node', 'created_fulldate', $options, $field['id']);
  169. break;
  170. case 'nid':
  171. if (!empty($field['options'])) {
  172. $options['not'] = TRUE;
  173. }
  174. $view->add_item($display, 'argument', 'node', 'nid', $options, $field['id']);
  175. break;
  176. }
  177. break;
  178. }
  179. }