flag_lists.views.inc 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <?php
  2. /**
  3. * @file
  4. * Provides support for the Views module.
  5. */
  6. /**
  7. * Implementation of hook_views_handlers().
  8. */
  9. function flag_lists_views_handlers() {
  10. return array(
  11. 'info' => array(
  12. 'path' => drupal_get_path('module', 'flag_lists') . '/includes',
  13. ),
  14. 'handlers' => array(
  15. 'flag_lists_handler_field_list' => array(
  16. 'parent' => 'views_handler_field',
  17. 'file' => 'flag_lists_handler_field_list.inc',
  18. ),
  19. 'flag_lists_handler_field_template' => array(
  20. 'parent' => 'views_handler_field',
  21. 'file' => 'flag_lists_handler_field_template.inc',
  22. ),
  23. 'flag_lists_handler_field_list_edit' => array(
  24. 'parent' => 'views_handler_field',
  25. 'file' => 'flag_lists_handler_field_list_edit.inc',
  26. ),
  27. 'flag_lists_handler_field_list_delete' => array(
  28. 'parent' => 'views_handler_field',
  29. 'file' => 'flag_lists_handler_field_list_delete.inc',
  30. ),
  31. 'flag_lists_handler_field_template_types' => array(
  32. 'parent' => 'views_handler_field_prerender_list',
  33. 'file' => 'flag_lists_handler_field_template_types.inc',
  34. ),
  35. 'flag_lists_handler_filter_template' => array(
  36. 'parent' => 'views_handler_filter_in_operator',
  37. 'file' => 'flag_lists_handler_filter_template.inc',
  38. ),
  39. 'flag_lists_handler_argument_fid' => array(
  40. 'parent' => 'views_handler_argument_numeric',
  41. 'file' => 'flag_lists_handler_argument_fid.inc',
  42. ),
  43. ),
  44. );
  45. }
  46. /**
  47. * Implementation of hook_views_data_alter().
  48. */
  49. function flag_lists_views_data_alter(&$data) {
  50. // We want access to users table fields.
  51. $data['users']['table']['join']['flag_lists_flags'] = array(
  52. 'left_field' => 'uid',
  53. 'field' => 'uid',
  54. );
  55. // We need fid and name form flags' data, and join.
  56. $data['flags'] = array(
  57. 'table' => array(
  58. 'group' => t('Flag'),
  59. 'join' => array(
  60. 'flag_lists_flags' => array(
  61. 'left_field' => 'pfid',
  62. 'field' => 'fid',
  63. ),
  64. ),
  65. ),
  66. 'fid' => array(
  67. 'title' => t('Flag fid'),
  68. 'help' => t('Flag id'),
  69. 'field' => array(
  70. 'click sortable' => TRUE,
  71. ),
  72. 'filter' => array(
  73. 'handler' => 'views_handler_filter_numeric',
  74. 'allow empty' => TRUE,
  75. ),
  76. 'argument' => array(
  77. 'handler' => 'views_handler_argument_numeric',
  78. ),
  79. 'sort' => array(
  80. 'handler' => 'views_handler_sort',
  81. ),
  82. ),
  83. 'name' => array(
  84. 'title' => t('Template name'),
  85. 'help' => t('The name of the list template flag'),
  86. 'field' => array(
  87. 'handler' => 'flag_lists_handler_field_template',
  88. 'click sortable' => TRUE,
  89. ),
  90. 'filter' => array(
  91. 'handler' => 'flag_lists_handler_filter_template',
  92. 'allow empty' => TRUE,
  93. ),
  94. 'sort' => array(
  95. 'handler' => 'views_handler_sort',
  96. ),
  97. ),
  98. );
  99. // Add the checkbox for flagging nodes VBO style, minus batch API
  100. foreach (entity_get_info() as $entity_type => $info) {
  101. if (isset($info['base table']) && $info['base table'] == 'node' && isset($data[$info['base table']])) {
  102. $data[$info['base table']]['flag_lists_ops'] = array(
  103. 'title' => t('Flag lists operations'),
  104. 'help' => t('Provide a checkbox to select the row for flag lists operations.'),
  105. 'real field' => $info['entity keys']['id'],
  106. 'field' => array(
  107. 'handler' => 'flag_lists_handler_field_ops',
  108. 'click sortable' => FALSE,
  109. ),
  110. );
  111. break;
  112. }
  113. }
  114. }
  115. /**
  116. * Implementation of hook_views_data().
  117. */
  118. function flag_lists_views_data() {
  119. $data = array();
  120. // flag_lists_flags data
  121. $data['flag_lists_flags'] = array(
  122. 'table' => array(
  123. 'base' => array(
  124. 'field' => 'fid',
  125. 'title' => t('Flag lists'),
  126. 'help' => 'User created flag lists',
  127. 'weight' => 10,
  128. 'database' => 'default',
  129. ),
  130. 'group' => t('Flag lists'),
  131. 'join' => array(
  132. 'node' => array(
  133. 'table' => 'flag_lists_flags',
  134. 'left_table' => 'flag_lists_content',
  135. 'left_field' => 'fid',
  136. 'field' => 'fid',
  137. ),
  138. ),
  139. ),
  140. 'fid' => array(
  141. 'title' => t('fid'),
  142. 'help' => t('Flag list id, required for Flag lists operationis\'s "unflag" action.'),
  143. 'field' => array(
  144. 'handler' => 'flag_lists_handler_field_list',
  145. 'click sortable' => TRUE,
  146. ),
  147. 'filter' => array(
  148. 'handler' => 'views_handler_filter_numeric',
  149. 'allow empty' => TRUE,
  150. ),
  151. 'argument' => array(
  152. 'handler' => 'flag_lists_handler_argument_fid',
  153. ),
  154. 'sort' => array(
  155. 'handler' => 'views_handler_sort',
  156. ),
  157. ),
  158. 'pfid' => array(
  159. 'title' => t('pfid'),
  160. 'help' => t('Template flag id'),
  161. 'field' => array(
  162. 'handler' => 'flag_lists_handler_field_pfid',
  163. 'click sortable' => TRUE,
  164. ),
  165. 'filter' => array(
  166. 'handler' => 'views_handler_filter_numeric',
  167. 'allow empty' => TRUE,
  168. ),
  169. 'argument' => array(
  170. 'handler' => 'views_handler_argument_numeric',
  171. ),
  172. 'sort' => array(
  173. 'handler' => 'views_handler_sort',
  174. ),
  175. ),
  176. 'uid' => array(
  177. 'title' => t('Uid'),
  178. 'help' => t('The list owner\'s uid'), // The help that appears on the UI,
  179. 'field' => array(
  180. 'handler' => 'views_handler_field_user',
  181. 'click sortable' => TRUE,
  182. ),
  183. 'argument' => array(
  184. 'handler' => 'views_handler_argument_user_uid',
  185. 'name field' => 'name', // display this field in the summary
  186. ),
  187. 'filter' => array(
  188. 'title' => t('Name'),
  189. 'handler' => 'views_handler_filter_user_name',
  190. ),
  191. 'sort' => array(
  192. 'handler' => 'views_handler_sort',
  193. ),
  194. ),
  195. 'name' => array(
  196. 'title' => t('machine name'),
  197. 'help' => t('Machine name of the list'),
  198. 'field' => array(
  199. 'handler' => 'flag_lists_handler_field_list',
  200. 'click sortable' => TRUE,
  201. ),
  202. 'filter' => array(
  203. 'handler' => 'views_handler_filter_string',
  204. 'allow empty' => TRUE,
  205. ),
  206. 'argument' => array(
  207. 'handler' => 'views_handler_argument_string',
  208. ),
  209. 'sort' => array(
  210. 'handler' => 'views_handler_sort',
  211. ),
  212. ),
  213. 'title' => array(
  214. 'title' => t('List title'),
  215. 'help' => t('Title of the list'),
  216. 'field' => array(
  217. 'click sortable' => TRUE,
  218. 'handler' => 'flag_lists_handler_field_list',
  219. ),
  220. 'filter' => array(
  221. 'handler' => 'views_handler_filter_string',
  222. 'allow empty' => TRUE,
  223. ),
  224. 'argument' => array(
  225. 'handler' => 'views_handler_argument_string',
  226. ),
  227. 'sort' => array(
  228. 'handler' => 'views_handler_sort',
  229. ),
  230. ),
  231. 'edit_list' => array(
  232. 'field' => array(
  233. 'title' => t('Edit link'),
  234. 'help' => t('Link to edit the list title'),
  235. 'handler' => 'flag_lists_handler_field_list_edit',
  236. ),
  237. ),
  238. 'delete_list' => array(
  239. 'field' => array(
  240. 'title' => t('Delete link'),
  241. 'help' => t('Link to delete the list'),
  242. 'handler' => 'flag_lists_handler_field_list_delete',
  243. ),
  244. ),
  245. );
  246. // Flag_lists_content data
  247. $data['flag_lists_content'] = array(
  248. 'table' => array(
  249. 'join' => array(
  250. 'node' => array(
  251. 'left_field' => 'nid',
  252. 'field' => 'content_id',
  253. ),
  254. ),
  255. 'group' => t('Flag lists'),
  256. ),
  257. 'uid' => array(
  258. 'relationship' => array(
  259. 'title' => t('User'),
  260. 'help' => t('The user who listed this node'),
  261. 'base' => 'users',
  262. 'handler' => 'views_handler_relationship',
  263. 'label' => t('List user'),
  264. ),
  265. ),
  266. 'content_id' => array(
  267. 'relationship' => array(
  268. 'title' => t('Node'),
  269. 'help' => t('The node that has been listed'),
  270. 'base' => 'node',
  271. 'handler' => 'views_handler_relationship',
  272. 'label' => t('Listed content'),
  273. ),
  274. ),
  275. 'timestamp' => array(
  276. 'title' => t('Time listed'),
  277. 'help' => t('The time this node was listed'),
  278. 'field' => array(
  279. 'handler' => 'views_handler_field_date',
  280. 'click sortable' => TRUE,
  281. ),
  282. 'filter' => array(
  283. 'handler' => 'views_handler_filter_numeric',
  284. 'allow empty' => TRUE,
  285. ),
  286. 'argument' => array(
  287. 'handler' => 'views_handler_argument_numeric',
  288. ),
  289. 'sort' => array(
  290. 'handler' => 'views_handler_sort',
  291. ),
  292. ),
  293. );
  294. // Flag_lists_types data
  295. $data['flag_lists_types'] = array(
  296. 'table' => array(
  297. 'group' => t('Flag lists'),
  298. 'join' => array(
  299. 'flag_lists_flags' => array(
  300. 'table' => 'flag_lists_types',
  301. 'type' => 'INNER',
  302. 'left_table' => 'flags',
  303. 'left_field' => 'name',
  304. 'field' => 'name',
  305. ),
  306. ),
  307. ),
  308. 'type' => array(
  309. 'title' => t('Template types'),
  310. 'help' => t('Node types that can be listed by lists using this template'),
  311. 'field' => array(
  312. 'click sortable' => FALSE,
  313. 'handler' => 'flag_lists_handler_field_template_types',
  314. ),
  315. ),
  316. );
  317. return $data;
  318. }