system.views.inc

  1. 3.x modules/system.views.inc
  2. 2.x modules/system.views.inc

Provide views data and handlers for system tables that are not represented by their own module.

File

modules/system.views.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. *
  5. * Provide views data and handlers for system tables that are not represented by
  6. * their own module.
  7. */
  8. /**
  9. * @defgroup views_system_module system.module handlers
  10. *
  11. * @{
  12. */
  13. /**
  14. * Implementation of hook_views_data()
  15. */
  16. function system_views_data() {
  17. $data = array();
  18. // ----------------------------------------------------------------------
  19. // files table
  20. $data['files']['table']['group'] = t('File');
  21. // Advertise this table as a possible base table
  22. $data['files']['table']['base'] = array(
  23. 'field' => 'fid',
  24. 'title' => t('File'),
  25. 'help' => t("Files maintained by Drupal and various modules."),
  26. );
  27. // The files table does not inherently join to the node table,
  28. // but may things (such as upload.module) can add relationships
  29. // that allow file fields to be used.
  30. // For other base tables, explain how we join
  31. $data['files']['table']['join'] = array(
  32. 'users' => array(
  33. // direct join to the users table via 'uid' field.
  34. 'left_field' => 'uid',
  35. 'field' => 'uid',
  36. ),
  37. );
  38. // fid
  39. $data['files']['fid'] = array(
  40. 'title' => t('File ID'),
  41. 'help' => t('The ID of the file.'),
  42. 'field' => array(
  43. 'handler' => 'views_handler_field_file',
  44. 'click sortable' => TRUE,
  45. ),
  46. 'argument' => array(
  47. 'handler' => 'views_handler_argument_file_fid',
  48. 'name field' => 'filename', // the field to display in the summary.
  49. ),
  50. 'filter' => array(
  51. 'handler' => 'views_handler_filter_numeric',
  52. ),
  53. 'sort' => array(
  54. 'handler' => 'views_handler_sort',
  55. ),
  56. );
  57. // filename
  58. $data['files']['filename'] = array(
  59. 'title' => t('Name'),
  60. 'help' => t('The name of the file.'),
  61. 'field' => array(
  62. 'handler' => 'views_handler_field_file',
  63. 'click sortable' => TRUE,
  64. ),
  65. 'sort' => array(
  66. 'handler' => 'views_handler_sort',
  67. ),
  68. 'filter' => array(
  69. 'handler' => 'views_handler_filter_string',
  70. ),
  71. 'argument' => array(
  72. 'handler' => 'views_handler_argument_string',
  73. ),
  74. );
  75. // filepath
  76. $data['files']['filepath'] = array(
  77. 'title' => t('Path'),
  78. 'help' => t('The path of the file.'),
  79. 'field' => array(
  80. 'handler' => 'views_handler_field_file',
  81. 'click sortable' => TRUE,
  82. ),
  83. 'sort' => array(
  84. 'handler' => 'views_handler_sort',
  85. ),
  86. 'filter' => array(
  87. 'handler' => 'views_handler_filter_string',
  88. ),
  89. 'argument' => array(
  90. 'handler' => 'views_handler_argument_string',
  91. ),
  92. );
  93. // filemime
  94. $data['files']['filemime'] = array(
  95. 'title' => t('Mime type'),
  96. 'help' => t('The mime type of the file.'),
  97. 'field' => array(
  98. 'handler' => 'views_handler_field_file',
  99. 'click sortable' => TRUE,
  100. ),
  101. 'sort' => array(
  102. 'handler' => 'views_handler_sort',
  103. ),
  104. 'filter' => array(
  105. 'handler' => 'views_handler_filter_string',
  106. ),
  107. 'argument' => array(
  108. 'handler' => 'views_handler_argument_string',
  109. ),
  110. );
  111. // filesize
  112. $data['files']['filesize'] = array(
  113. 'title' => t('Size'),
  114. 'help' => t('The size of the file.'),
  115. 'field' => array(
  116. 'handler' => 'views_handler_field_file_size',
  117. 'click sortable' => TRUE,
  118. ),
  119. 'sort' => array(
  120. 'handler' => 'views_handler_sort',
  121. ),
  122. 'filter' => array(
  123. 'handler' => 'views_handler_filter_numeric',
  124. ),
  125. );
  126. // status
  127. $data['files']['status'] = array(
  128. 'title' => t('Status'),
  129. 'help' => t('The status of the file.'),
  130. 'field' => array(
  131. 'handler' => 'views_handler_field_file_status',
  132. 'click sortable' => TRUE,
  133. ),
  134. 'sort' => array(
  135. 'handler' => 'views_handler_sort',
  136. ),
  137. 'filter' => array(
  138. 'handler' => 'views_handler_filter_file_status',
  139. ),
  140. );
  141. // timestamp field
  142. $data['files']['timestamp'] = array(
  143. 'title' => t('Upload date'),
  144. 'help' => t('The date the file was uploaded.'),
  145. 'field' => array(
  146. 'handler' => 'views_handler_field_date',
  147. 'click sortable' => TRUE,
  148. ),
  149. 'sort' => array(
  150. 'handler' => 'views_handler_sort_date',
  151. ),
  152. 'filter' => array(
  153. 'handler' => 'views_handler_filter_date',
  154. ),
  155. );
  156. // uid field
  157. $data['files']['uid'] = array(
  158. 'title' => t('User'),
  159. 'help' => t('The user, who uploaded the file.'),
  160. 'relationship' => array(
  161. 'base' => 'users',
  162. 'base field' => 'uid',
  163. 'handler' => 'views_handler_relationship',
  164. 'label' => t('User'),
  165. ),
  166. );
  167. return $data;
  168. }
  169. /**
  170. * Implementation of hook_views_handlers() to register all of the basic handlers
  171. * views uses.
  172. */
  173. function system_views_handlers() {
  174. return array(
  175. 'info' => array(
  176. 'path' => drupal_get_path('module', 'views') . '/modules/system',
  177. ),
  178. 'handlers' => array(
  179. 'views_handler_field_file' => array(
  180. 'parent' => 'views_handler_field',
  181. ),
  182. 'views_handler_field_file_status' => array(
  183. 'parent' => 'views_handler_field',
  184. ),
  185. 'views_handler_filter_file_status' => array(
  186. 'parent' => 'views_handler_filter_in_operator',
  187. ),
  188. 'views_handler_argument_file_fid' => array(
  189. 'parent' => 'views_handler_argument',
  190. ),
  191. ),
  192. );
  193. }
  194. function _views_file_status($choice = NULL) {
  195. $status = array(
  196. FILE_STATUS_TEMPORARY => t('Temporary'),
  197. FILE_STATUS_PERMANENT => t('Permanent'),
  198. );
  199. if (isset($choice)) {
  200. return isset($status[$choice]) ? $status[$choice] : t('Unknown');
  201. }
  202. return $status;
  203. }
  204. /**
  205. * @}
  206. */