function file_field_views_data_views_data_alter in Views (for Drupal 7) 7.3
Same name and namespace in other branches
- 8.3 modules/file.views.inc \file_field_views_data_views_data_alter()
Implements hook_field_views_data_views_data_alter().
Views integration to provide reverse relationships on file fields.
File
- modules/
file.views.inc, line 39 - Provide views data and handlers for file.module.
Code
function file_field_views_data_views_data_alter(&$data, $field) {
foreach ($field['bundles'] as $entity_type => $bundles) {
$entity_info = entity_get_info($entity_type);
$pseudo_field_name = 'reverse_' . $field['field_name'] . '_' . $entity_type;
list($label, $all_labels) = field_views_field_label($field['field_name']);
$entity = $entity_info['label'];
if ($entity == t('Node')) {
$entity = t('Content');
}
$data['file_managed'][$pseudo_field_name]['relationship'] = array(
'title' => t('@entity using @field', array(
'@entity' => $entity,
'@field' => $label,
)),
'help' => t('Relate each @entity with a @field set to the file.', array(
'@entity' => $entity,
'@field' => $label,
)),
'handler' => 'views_handler_relationship_entity_reverse',
'field_name' => $field['field_name'],
'field table' => _field_sql_storage_tablename($field),
'field field' => $field['field_name'] . '_fid',
'base' => $entity_info['base table'],
'base field' => $entity_info['entity keys']['id'],
'label' => t('!field_name', array(
'!field_name' => $field['field_name'],
)),
'join_extra' => array(
0 => array(
'field' => 'entity_type',
'value' => $entity_type,
),
1 => array(
'field' => 'deleted',
'value' => 0,
'numeric' => TRUE,
),
),
);
}
}