file.views.inc

  1. cis7 sites/all/modules/ulmus/views/modules/file.views.inc
  2. cle7 sites/all/modules/ulmus/views/modules/file.views.inc
  3. ecd7 sites/all/modules/ulmus/views/modules/file.views.inc
  4. elmsmedia7 sites/all/modules/ulmus/views/modules/file.views.inc
  5. harmony7 sites/all/modules/ulmus/views/modules/file.views.inc
  6. icor7 sites/all/modules/ulmus/views/modules/file.views.inc
  7. meedjum_blog7 sites/all/modules/ulmus/views/modules/file.views.inc
  8. mooc7 sites/all/modules/ulmus/views/modules/file.views.inc

Provide views data and handlers for file.module.

Functions

Namesort descending Description
file_field_views_data Implements hook_field_views_data().
file_field_views_data_views_data_alter Implements hook_field_views_data_views_data_alter().

File

sites/all/modules/ulmus/views/modules/file.views.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Provide views data and handlers for file.module.
  5. *
  6. * @ingroup views_module_handlers
  7. */
  8. /**
  9. * Implements hook_field_views_data().
  10. *
  11. * Views integration for file fields. Adds a file relationship to the default
  12. * field data.
  13. *
  14. * @see field_views_field_default_views_data()
  15. */
  16. function file_field_views_data($field) {
  17. $data = field_views_field_default_views_data($field);
  18. foreach ($data as $table_name => $table_data) {
  19. // Add the relationship only on the fid field.
  20. $data[$table_name][$field['field_name'] . '_fid']['relationship'] = array(
  21. 'handler' => 'views_handler_relationship',
  22. 'base' => 'file_managed',
  23. 'entity type' => 'file',
  24. 'base field' => 'fid',
  25. 'label' => t('file from !field_name', array('!field_name' => $field['field_name'])),
  26. );
  27. }
  28. return $data;
  29. }
  30. /**
  31. * Implements hook_field_views_data_views_data_alter().
  32. *
  33. * Views integration to provide reverse relationships on file fields.
  34. */
  35. function file_field_views_data_views_data_alter(&$data, $field) {
  36. foreach ($field['bundles'] as $entity_type => $bundles) {
  37. $entity_info = entity_get_info($entity_type);
  38. $pseudo_field_name = 'reverse_' . $field['field_name'] . '_' . $entity_type;
  39. list($label, $all_labels) = field_views_field_label($field['field_name']);
  40. $entity = $entity_info['label'];
  41. if ($entity == t('Node')) {
  42. $entity = t('Content');
  43. }
  44. $data['file_managed'][$pseudo_field_name]['relationship'] = array(
  45. 'title' => t('@entity using @field', array('@entity' => $entity, '@field' => $label)),
  46. 'help' => t('Relate each @entity with a @field set to the file.', array('@entity' => $entity, '@field' => $label)),
  47. 'handler' => 'views_handler_relationship_entity_reverse',
  48. 'field_name' => $field['field_name'],
  49. 'field table' => _field_sql_storage_tablename($field),
  50. 'field field' => $field['field_name'] . '_fid',
  51. 'base' => $entity_info['base table'],
  52. 'base field' => $entity_info['entity keys']['id'],
  53. 'label' => t('!field_name', array('!field_name' => $field['field_name'])),
  54. 'join_extra' => array(
  55. 0 => array(
  56. 'field' => 'entity_type',
  57. 'value' => $entity_type,
  58. ),
  59. 1 => array(
  60. 'field' => 'deleted',
  61. 'value' => 0,
  62. 'numeric' => TRUE,
  63. ),
  64. ),
  65. );
  66. }
  67. }

Related topics