flag_lists.views.inc 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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['flag'] = 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' => 'flag_lists_handler_filter_list',
  222. ),
  223. 'argument' => array(
  224. 'handler' => 'views_handler_argument_string',
  225. ),
  226. 'sort' => array(
  227. 'handler' => 'views_handler_sort',
  228. ),
  229. ),
  230. 'edit_list' => array(
  231. 'field' => array(
  232. 'title' => t('Edit link'),
  233. 'help' => t('Link to edit the list title'),
  234. 'handler' => 'flag_lists_handler_field_list_edit',
  235. ),
  236. ),
  237. 'delete_list' => array(
  238. 'field' => array(
  239. 'title' => t('Delete link'),
  240. 'help' => t('Link to delete the list'),
  241. 'handler' => 'flag_lists_handler_field_list_delete',
  242. ),
  243. ),
  244. );
  245. // Flag_lists_content data
  246. $data['flag_lists_content'] = array(
  247. 'table' => array(
  248. 'join' => array(
  249. 'node' => array(
  250. 'left_field' => 'nid',
  251. 'field' => 'entity_id',
  252. ),
  253. ),
  254. 'group' => t('Flag lists'),
  255. ),
  256. 'uid' => array(
  257. 'relationship' => array(
  258. 'title' => t('User'),
  259. 'help' => t('The user who listed this node'),
  260. 'base' => 'users',
  261. 'handler' => 'views_handler_relationship',
  262. 'label' => t('List user'),
  263. ),
  264. ),
  265. 'entity_id' => array(
  266. 'relationship' => array(
  267. 'title' => t('Node'),
  268. 'help' => t('The node that has been listed'),
  269. 'base' => 'node',
  270. 'handler' => 'views_handler_relationship',
  271. 'label' => t('Listed content'),
  272. ),
  273. ),
  274. 'timestamp' => array(
  275. 'title' => t('Time listed'),
  276. 'help' => t('The time this node was listed'),
  277. 'field' => array(
  278. 'handler' => 'views_handler_field_date',
  279. 'click sortable' => TRUE,
  280. ),
  281. 'filter' => array(
  282. 'handler' => 'views_handler_filter_numeric',
  283. 'allow empty' => TRUE,
  284. ),
  285. 'argument' => array(
  286. 'handler' => 'views_handler_argument_numeric',
  287. ),
  288. 'sort' => array(
  289. 'handler' => 'views_handler_sort',
  290. ),
  291. ),
  292. );
  293. // Flag_lists_types data
  294. $data['flag_lists_types'] = array(
  295. 'table' => array(
  296. 'group' => t('Flag lists'),
  297. 'join' => array(
  298. 'flag_lists_flags' => array(
  299. 'table' => 'flag_lists_types',
  300. 'type' => 'INNER',
  301. 'left_table' => 'flag',
  302. 'left_field' => 'name',
  303. 'field' => 'name',
  304. ),
  305. ),
  306. ),
  307. 'type' => array(
  308. 'title' => t('Template types'),
  309. 'help' => t('Node types that can be listed by lists using this template'),
  310. 'field' => array(
  311. 'click sortable' => FALSE,
  312. 'handler' => 'flag_lists_handler_field_template_types',
  313. ),
  314. ),
  315. );
  316. return $data;
  317. }