function ref_field_field_views_data in (Entity)Reference Field Synchronization 7
Implements hook_field_views_data().
File
- includes/
views/ ref_field.views.inc, line 12
Code
function ref_field_field_views_data($field) {
// Get default views field values
$data = field_views_field_default_views_data($field);
// Get references entity info
$entity_info = entity_get_info($field['settings']['entity']);
foreach ($data as $table_name => $table_data) {
// Check if base tables is set
// Is this needed? Don't they all have one?
if (isset($entity_info['base table'])) {
$entity = $entity_info['label'];
// If a node, name it as Content
// Consistent UI (?)
if ($entity == t('Node')) {
$entity = t('Content');
}
// Add relationship to the field
$field_name = $field['field_name'] . '_eid';
$data[$table_name][$field_name]['relationship'] = array(
'handler' => 'views_handler_relationship',
'base' => $entity_info['base table'],
'base field' => $entity_info['entity keys']['id'],
'label' => t('@entity entity referenced from !field_name', array(
'@entity' => $entity,
'!field_name' => $field['field_name'],
)),
'group' => t('Entity Reference'),
'title' => t('Referenced @entity', array(
'@entity' => $entity,
)),
'help' => t('Relate any @entity referenced via !field_name. This relationship will cause duplicated records if there is more than one @entity referenced.', array(
'@entity' => $entity,
'!field_name' => $field['field_name'],
)),
);
}
}
return $data;
}