system.views.inc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. <?php
  2. /**
  3. * @file
  4. * Provide views data and handlers for system.module.
  5. *
  6. * @ingroup views_module_handlers
  7. */
  8. /**
  9. * Implements hook_views_data().
  10. */
  11. function system_views_data() {
  12. $data = array();
  13. // ----------------------------------------------------------------------
  14. // 'file_managed' table.
  15. $data['files']['moved to'] = 'file_managed';
  16. $data['file_managed']['table']['group'] = t('File');
  17. // Advertise this table as a possible base table.
  18. $data['file_managed']['table']['base'] = array(
  19. 'field' => 'fid',
  20. 'title' => t('File'),
  21. 'help' => t("Files maintained by Drupal and various modules."),
  22. 'defaults' => array(
  23. 'field' => 'filename',
  24. ),
  25. );
  26. $data['file_managed']['table']['entity type'] = 'file';
  27. // File ID / 'fid'.
  28. $data['file_managed']['fid'] = array(
  29. 'title' => t('File ID'),
  30. 'help' => t('The ID of the file.'),
  31. 'field' => array(
  32. 'handler' => 'views_handler_field_file',
  33. 'click sortable' => TRUE,
  34. ),
  35. 'argument' => array(
  36. 'handler' => 'views_handler_argument_file_fid',
  37. 'name field' => 'filename',
  38. // the field to display in the summary.
  39. 'numeric' => TRUE,
  40. ),
  41. 'filter' => array(
  42. 'handler' => 'views_handler_filter_numeric',
  43. ),
  44. 'sort' => array(
  45. 'handler' => 'views_handler_sort',
  46. ),
  47. );
  48. // Filename.
  49. $data['file_managed']['filename'] = array(
  50. 'title' => t('Name'),
  51. 'help' => t('The name of the file.'),
  52. 'field' => array(
  53. 'handler' => 'views_handler_field_file',
  54. 'click sortable' => TRUE,
  55. ),
  56. 'sort' => array(
  57. 'handler' => 'views_handler_sort',
  58. ),
  59. 'filter' => array(
  60. 'handler' => 'views_handler_filter_string',
  61. ),
  62. 'argument' => array(
  63. 'handler' => 'views_handler_argument_string',
  64. ),
  65. );
  66. // URI.
  67. $data['file_managed']['uri'] = array(
  68. 'title' => t('Path'),
  69. 'help' => t('The path of the file.'),
  70. 'field' => array(
  71. 'handler' => 'views_handler_field_file_uri',
  72. 'click sortable' => TRUE,
  73. ),
  74. 'sort' => array(
  75. 'handler' => 'views_handler_sort',
  76. ),
  77. 'filter' => array(
  78. 'handler' => 'views_handler_filter_string',
  79. ),
  80. 'argument' => array(
  81. 'handler' => 'views_handler_argument_string',
  82. ),
  83. );
  84. // The file's MIME Type.
  85. $data['file_managed']['filemime'] = array(
  86. 'title' => t('Mime type'),
  87. 'help' => t('The mime type of the file.'),
  88. 'field' => array(
  89. 'handler' => 'views_handler_field_file_filemime',
  90. 'click sortable' => TRUE,
  91. ),
  92. 'sort' => array(
  93. 'handler' => 'views_handler_sort',
  94. ),
  95. 'filter' => array(
  96. 'handler' => 'views_handler_filter_string',
  97. ),
  98. 'argument' => array(
  99. 'handler' => 'views_handler_argument_string',
  100. ),
  101. );
  102. // Extension.
  103. $data['file_managed']['extension'] = array(
  104. 'title' => t('Extension'),
  105. 'help' => t('The extension of the file.'),
  106. 'real field' => 'filename',
  107. 'field' => array(
  108. 'handler' => 'views_handler_field_file_extension',
  109. 'click sortable' => FALSE,
  110. ),
  111. );
  112. // Filesize.
  113. $data['file_managed']['filesize'] = array(
  114. 'title' => t('Size'),
  115. 'help' => t('The size of the file.'),
  116. 'field' => array(
  117. 'handler' => 'views_handler_field_file_size',
  118. 'click sortable' => TRUE,
  119. ),
  120. 'sort' => array(
  121. 'handler' => 'views_handler_sort',
  122. ),
  123. 'filter' => array(
  124. 'handler' => 'views_handler_filter_numeric',
  125. ),
  126. );
  127. // Status.
  128. $data['file_managed']['status'] = array(
  129. 'title' => t('Status'),
  130. 'help' => t('The status of the file.'),
  131. 'field' => array(
  132. 'handler' => 'views_handler_field_file_status',
  133. 'click sortable' => TRUE,
  134. ),
  135. 'sort' => array(
  136. 'handler' => 'views_handler_sort',
  137. ),
  138. 'filter' => array(
  139. 'handler' => 'views_handler_filter_file_status',
  140. ),
  141. );
  142. // Timestamp field.
  143. $data['file_managed']['timestamp'] = array(
  144. 'title' => t('Upload date'),
  145. 'help' => t('The date the file was uploaded.'),
  146. 'field' => array(
  147. 'handler' => 'views_handler_field_date',
  148. 'click sortable' => TRUE,
  149. ),
  150. 'sort' => array(
  151. 'handler' => 'views_handler_sort_date',
  152. ),
  153. 'filter' => array(
  154. 'handler' => 'views_handler_filter_date',
  155. ),
  156. );
  157. // User ID / 'uid'.
  158. $data['file_managed']['uid'] = array(
  159. 'title' => t('User who uploaded'),
  160. 'help' => t('The user that uploaded the file.'),
  161. 'relationship' => array(
  162. 'title' => t('User who uploaded'),
  163. 'label' => t('User who uploaded'),
  164. 'base' => 'users',
  165. 'base field' => 'uid',
  166. ),
  167. );
  168. // ----------------------------------------------------------------------
  169. // file_usage table.
  170. $data['file_usage']['table']['group'] = t('File Usage');
  171. // Provide field-type-things to several base tables; on the core files table
  172. // ("file_managed") so that we can create relationships from files to
  173. // entities, and then on each core entity type base table so that we can
  174. // provide general relationships between entities and files.
  175. $data['file_usage']['table']['join'] = array(
  176. // Link ourself to the {file_managed} table so we can provide file->entity
  177. // relationships.
  178. 'file_managed' => array(
  179. 'field' => 'fid',
  180. 'left_field' => 'fid',
  181. ),
  182. // Link ourself to the {node} table so we can provide node->file
  183. // relationships.
  184. 'node' => array(
  185. 'field' => 'id',
  186. 'left_field' => 'nid',
  187. 'extra' => array(array('field' => 'type', 'value' => 'node')),
  188. ),
  189. // Link ourself to the {users} table so we can provide user->file
  190. // relationships.
  191. 'users' => array(
  192. 'field' => 'id',
  193. 'left_field' => 'uid',
  194. 'extra' => array(array('field' => 'type', 'value' => 'user')),
  195. ),
  196. // Link ourself to the {comment} table so we can provide comment->file
  197. // relationships.
  198. 'comment' => array(
  199. 'field' => 'id',
  200. 'left_field' => 'cid',
  201. 'extra' => array(array('field' => 'type', 'value' => 'comment')),
  202. ),
  203. // Link ourself to the {taxonomy_term_data} table so we can provide
  204. // taxonomy_term->file relationships.
  205. 'taxonomy_term_data' => array(
  206. 'field' => 'id',
  207. 'left_field' => 'tid',
  208. 'extra' => array(array('field' => 'type', 'value' => 'taxonomy_term')),
  209. ),
  210. // Link ourself to the {taxonomy_vocabulary} table so we can provide
  211. // taxonomy_vocabulary->file relationships.
  212. 'taxonomy_vocabulary' => array(
  213. 'field' => 'id',
  214. 'left_field' => 'vid',
  215. 'extra' => array(array('field' => 'type', 'value' => 'taxonomy_vocabulary')),
  216. ),
  217. );
  218. // Provide a relationship between the files table and each entity type, and
  219. // between each entity type and the files table. Entity->file relationships
  220. // are type-restricted in the joins declared above, and file->entity
  221. // relationships are type-restricted in the relationship declarations below.
  222. // Relationships between files and nodes.
  223. $data['file_usage']['file_to_node'] = array(
  224. 'title' => t('Content'),
  225. 'help' => t('Content that is associated with this file, usually because this file is in a field on the content.'),
  226. // Only provide this field/relationship/etc. when the 'file_managed' base
  227. // table is present.
  228. 'skip base' => array('node', 'node_revision', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'),
  229. 'real field' => 'id',
  230. 'relationship' => array(
  231. 'title' => t('Content'),
  232. 'label' => t('Content'),
  233. 'base' => 'node',
  234. 'base field' => 'nid',
  235. 'relationship field' => 'id',
  236. 'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'node')),
  237. ),
  238. );
  239. $data['file_usage']['node_to_file'] = array(
  240. 'title' => t('File'),
  241. 'help' => t('A file that is associated with this node, usually because it is in a field on the node.'),
  242. // Only provide this field/relationship/etc. when the 'node' base table is
  243. // present.
  244. 'skip base' => array('file_managed', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'),
  245. 'real field' => 'fid',
  246. 'relationship' => array(
  247. 'title' => t('File'),
  248. 'label' => t('File'),
  249. 'base' => 'file_managed',
  250. 'base field' => 'fid',
  251. 'relationship field' => 'fid',
  252. ),
  253. );
  254. // Relationships between files and users.
  255. $data['file_usage']['file_to_user'] = array(
  256. 'title' => t('User'),
  257. 'help' => t('A user that is associated with this file, usually because this file is in a field on the user.'),
  258. // Only provide this field/relationship/etc. when the 'file_managed' base
  259. // table is present.
  260. 'skip base' => array('node', 'node_revision', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'),
  261. 'real field' => 'id',
  262. 'relationship' => array(
  263. 'title' => t('User'),
  264. 'label' => t('User'),
  265. 'base' => 'users',
  266. 'base field' => 'uid',
  267. 'relationship field' => 'id',
  268. 'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'user')),
  269. ),
  270. );
  271. $data['file_usage']['user_to_file'] = array(
  272. 'title' => t('File'),
  273. 'help' => t('A file that is associated with this user, usually because it is in a field on the user.'),
  274. // Only provide this field/relationship/etc. when the 'users' base table is
  275. // present.
  276. 'skip base' => array('file_managed', 'node', 'node_revision', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'),
  277. 'real field' => 'fid',
  278. 'relationship' => array(
  279. 'title' => t('File'),
  280. 'label' => t('File'),
  281. 'base' => 'file_managed',
  282. 'base field' => 'fid',
  283. 'relationship field' => 'fid',
  284. ),
  285. );
  286. // Relationships between files and comments.
  287. $data['file_usage']['file_to_comment'] = array(
  288. 'title' => t('Comment'),
  289. 'help' => t('A comment that is associated with this file, usually because this file is in a field on the comment.'),
  290. // Only provide this field/relationship/etc. when the 'file_managed' base
  291. // table is present.
  292. 'skip base' => array('node', 'node_revision', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'),
  293. 'real field' => 'id',
  294. 'relationship' => array(
  295. 'title' => t('Comment'),
  296. 'label' => t('Comment'),
  297. 'base' => 'comment',
  298. 'base field' => 'cid',
  299. 'relationship field' => 'id',
  300. 'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'comment')),
  301. ),
  302. );
  303. $data['file_usage']['comment_to_file'] = array(
  304. 'title' => t('File'),
  305. 'help' => t('A file that is associated with this comment, usually because it is in a field on the comment.'),
  306. // Only provide this field/relationship/etc. when the 'comment' base table
  307. // is present.
  308. 'skip base' => array('file_managed', 'node', 'node_revision', 'users', 'taxonomy_term_data', 'taxonomy_vocabulary'),
  309. 'real field' => 'fid',
  310. 'relationship' => array(
  311. 'title' => t('File'),
  312. 'label' => t('File'),
  313. 'base' => 'file_managed',
  314. 'base field' => 'fid',
  315. 'relationship field' => 'fid',
  316. ),
  317. );
  318. // Relationships between files and taxonomy_terms.
  319. $data['file_usage']['file_to_taxonomy_term'] = array(
  320. 'title' => t('Taxonomy Term'),
  321. 'help' => t('A taxonomy term that is associated with this file, usually because this file is in a field on the taxonomy term.'),
  322. // Only provide this field/relationship/etc. when the 'file_managed' base
  323. // table is present.
  324. 'skip base' => array('node', 'node_revision', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'),
  325. 'real field' => 'id',
  326. 'relationship' => array(
  327. 'title' => t('Taxonomy Term'),
  328. 'label' => t('Taxonomy Term'),
  329. 'base' => 'taxonomy_term_data',
  330. 'base field' => 'tid',
  331. 'relationship field' => 'id',
  332. 'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'taxonomy_term')),
  333. ),
  334. );
  335. $data['file_usage']['taxonomy_term_to_file'] = array(
  336. 'title' => t('File'),
  337. 'help' => t('A file that is associated with this taxonomy term, usually because it is in a field on the taxonomy term.'),
  338. // Only provide this field/relationship/etc. when the 'taxonomy_term_data'
  339. // base table is present.
  340. 'skip base' => array('file_managed', 'node', 'node_revision', 'users', 'comment', 'taxonomy_vocabulary'),
  341. 'real field' => 'fid',
  342. 'relationship' => array(
  343. 'title' => t('File'),
  344. 'label' => t('File'),
  345. 'base' => 'file_managed',
  346. 'base field' => 'fid',
  347. 'relationship field' => 'fid',
  348. ),
  349. );
  350. // Relationships between files and taxonomy_vocabulary items.
  351. $data['file_usage']['file_to_taxonomy_vocabulary'] = array(
  352. 'title' => t('Taxonomy Vocabulary'),
  353. 'help' => t('A taxonomy vocabulary that is associated with this file, usually because this file is in a field on the taxonomy vocabulary.'),
  354. // Only provide this field/relationship/etc. when the 'file_managed' base
  355. // table is present.
  356. 'skip base' => array('node', 'node_revision', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'),
  357. 'real field' => 'id',
  358. 'relationship' => array(
  359. 'title' => t('Taxonomy Vocabulary'),
  360. 'label' => t('Taxonomy Vocabulary'),
  361. 'base' => 'taxonomy_vocabulary',
  362. 'base field' => 'vid',
  363. 'relationship field' => 'id',
  364. 'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'taxonomy_vocabulary')),
  365. ),
  366. );
  367. $data['file_usage']['taxonomy_vocabulary_to_file'] = array(
  368. 'title' => t('File'),
  369. 'help' => t('A file that is associated with this taxonomy vocabulary, usually because it is in a field on the taxonomy vocabulary.'),
  370. // Only provide this field/relationship/etc. when the 'taxonomy_vocabulary'
  371. // base table is present.
  372. 'skip base' => array('file_managed', 'node', 'node_revision', 'users', 'comment', 'taxonomy_term_data'),
  373. 'real field' => 'fid',
  374. 'relationship' => array(
  375. 'title' => t('File'),
  376. 'label' => t('File'),
  377. 'base' => 'file_managed',
  378. 'base field' => 'fid',
  379. 'relationship field' => 'fid',
  380. ),
  381. );
  382. // Provide basic fields from the {file_usage} table to all of the base tables
  383. // we've declared joins to (because there is no 'skip base' property on these
  384. // fields).
  385. $data['file_usage']['module'] = array(
  386. 'title' => t('Module'),
  387. 'help' => t('The module managing this file relationship.'),
  388. 'field' => array(
  389. 'handler' => 'views_handler_field',
  390. 'click sortable' => TRUE,
  391. ),
  392. 'filter' => array(
  393. 'handler' => 'views_handler_filter_string',
  394. ),
  395. 'argument' => array(
  396. 'handler' => 'views_handler_argument_string',
  397. ),
  398. 'sort' => array(
  399. 'handler' => 'views_handler_sort',
  400. ),
  401. );
  402. $data['file_usage']['type'] = array(
  403. 'title' => t('Entity type'),
  404. 'help' => t('The type of entity that is related to the file.'),
  405. 'field' => array(
  406. 'handler' => 'views_handler_field',
  407. 'click sortable' => TRUE,
  408. ),
  409. 'filter' => array(
  410. 'handler' => 'views_handler_filter_string',
  411. ),
  412. 'argument' => array(
  413. 'handler' => 'views_handler_argument_string',
  414. ),
  415. 'sort' => array(
  416. 'handler' => 'views_handler_sort',
  417. ),
  418. );
  419. $data['file_usage']['id'] = array(
  420. 'title' => t('Entity ID'),
  421. 'help' => t('The ID of the entity that is related to the file.'),
  422. 'field' => array(
  423. 'handler' => 'views_handler_field_numeric',
  424. 'click sortable' => TRUE,
  425. ),
  426. 'argument' => array(
  427. 'handler' => 'views_handler_argument_numeric',
  428. ),
  429. 'filter' => array(
  430. 'handler' => 'views_handler_filter_numeric',
  431. ),
  432. 'sort' => array(
  433. 'handler' => 'views_handler_sort',
  434. ),
  435. );
  436. $data['file_usage']['count'] = array(
  437. 'title' => t('Use count'),
  438. 'help' => t('The number of times the file is used by this entity.'),
  439. 'field' => array(
  440. 'handler' => 'views_handler_field_numeric',
  441. 'click sortable' => TRUE,
  442. ),
  443. 'filter' => array(
  444. 'handler' => 'views_handler_filter_numeric',
  445. ),
  446. 'sort' => array(
  447. 'handler' => 'views_handler_sort',
  448. ),
  449. );
  450. // ----------------------------------------------------------------------
  451. // System table.
  452. $data['system']['table']['group'] = t('System');
  453. // Advertise this table as a possible base table.
  454. $data['system']['table']['base'] = array(
  455. 'field' => 'filename',
  456. 'title' => t('Module/Theme/Theme engine'),
  457. 'help' => t('Modules/Themes/Theme engines in your codebase.'),
  458. );
  459. // Fields.
  460. // - filename.
  461. $data['system']['filename'] = array(
  462. 'title' => t('Module/Theme/Theme engine filename'),
  463. 'help' => t('The path of the primary file for this item, relative to the Drupal root; e.g. modules/node/node.module.'),
  464. 'field' => array(
  465. 'handler' => 'views_handler_field',
  466. 'click sortable' => TRUE,
  467. ),
  468. 'argument' => array(
  469. // The field to display in the summary.
  470. 'handler' => 'views_handler_argument_string',
  471. 'name field' => 'filename',
  472. ),
  473. 'filter' => array(
  474. 'handler' => 'views_handler_filter_string',
  475. ),
  476. 'sort' => array(
  477. 'handler' => 'views_handler_sort',
  478. ),
  479. );
  480. // - name.
  481. $data['system']['name'] = array(
  482. 'title' => t('Module/Theme/Theme engine name'),
  483. 'help' => t('The name of the item; e.g. node.'),
  484. 'field' => array(
  485. 'handler' => 'views_handler_field',
  486. 'click sortable' => TRUE,
  487. ),
  488. 'argument' => array(
  489. // The field to display in the summary.
  490. 'handler' => 'views_handler_argument_string',
  491. 'name field' => 'name',
  492. ),
  493. 'filter' => array(
  494. 'handler' => 'views_handler_filter_string',
  495. ),
  496. 'sort' => array(
  497. 'handler' => 'views_handler_sort',
  498. ),
  499. );
  500. // - type.
  501. $data['system']['type'] = array(
  502. 'title' => t('Type'),
  503. 'help' => t('The type of the item, either module, theme, or theme_engine.'),
  504. 'field' => array(
  505. 'handler' => 'views_handler_field',
  506. 'click sortable' => TRUE,
  507. ),
  508. 'argument' => array(
  509. // The field to display in the summary.
  510. 'handler' => 'views_handler_argument_string',
  511. 'name field' => 'type',
  512. ),
  513. 'filter' => array(
  514. 'handler' => 'views_handler_filter_system_type',
  515. ),
  516. 'sort' => array(
  517. 'handler' => 'views_handler_sort',
  518. ),
  519. );
  520. // - status.
  521. $data['system']['status'] = array(
  522. 'title' => t('Status'),
  523. 'help' => t('Boolean indicating whether or not this item is enabled.'),
  524. 'field' => array(
  525. 'handler' => 'views_handler_field_boolean',
  526. 'click sortable' => TRUE,
  527. ),
  528. 'argument' => array(
  529. // The field to display in the summary.
  530. 'handler' => 'views_handler_argument_numeric',
  531. 'name field' => 'status',
  532. ),
  533. 'filter' => array(
  534. 'handler' => 'views_handler_filter_boolean_operator',
  535. ),
  536. 'sort' => array(
  537. 'handler' => 'views_handler_sort',
  538. ),
  539. );
  540. // - schema version.
  541. $data['system']['schema_version'] = array(
  542. 'title' => t('Schema version'),
  543. 'help' => t("The module's database schema version number. -1 if the module is not installed (its tables do not exist); 0 or the largest N of the module's hook_update_N() function that has either been run or existed when the module was first installed."),
  544. 'field' => array(
  545. 'handler' => 'views_handler_field_numeric',
  546. 'click sortable' => TRUE,
  547. ),
  548. 'argument' => array(
  549. // The field to display in the summary.
  550. 'handler' => 'views_handler_argument_numeric',
  551. 'name field' => 'schema_version',
  552. ),
  553. 'filter' => array(
  554. 'handler' => 'views_handler_filter_numeric',
  555. ),
  556. 'sort' => array(
  557. 'handler' => 'views_handler_sort',
  558. ),
  559. );
  560. return $data;
  561. }
  562. /**
  563. * Obtain a human readable label for a file's status.
  564. *
  565. * @param int $choice
  566. * Indicate the file's status, expected to be either '0' for a temporary file
  567. * or the value of FILE_STATUS_PERMANENT for a permanent file; any other value
  568. * will be indicated as being 'Unknown'.
  569. *
  570. * @return string
  571. * A string representing the file's status.
  572. */
  573. function _views_file_status($choice = NULL) {
  574. $status = array(
  575. 0 => t('Temporary'),
  576. FILE_STATUS_PERMANENT => t('Permanent'),
  577. );
  578. if (isset($choice)) {
  579. return isset($status[$choice]) ? $status[$choice] : t('Unknown');
  580. }
  581. return $status;
  582. }