You are here

function entityreference_field_views_data in Entity reference 7

Implements hook_field_views_data().

File

views/entityreference.views.inc, line 11
Views integration for Entity Reference.

Code

function entityreference_field_views_data($field) {
  $data = field_views_field_default_views_data($field);
  $entity_info = entity_get_info($field['settings']['target_type']);
  foreach ($data as $table_name => $table_data) {
    if (isset($entity_info['base table'])) {
      $entity = $entity_info['label'];
      if ($entity == t('Node')) {
        $entity = t('Content');
      }
      $field_name = $field['field_name'] . '_target_id';
      $parameters = array(
        '@entity' => $entity,
        '!field_name' => $field['field_name'],
      );
      $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', $parameters),
        'group' => t('Entity Reference'),
        'title' => t('Referenced Entity'),
        'help' => t('A bridge to the @entity entity that is referenced via !field_name', $parameters),
      );
    }
  }

  // Invoke the behaviors to allow them to change the properties.
  foreach (entityreference_get_behavior_handlers($field) as $handler) {
    $handler
      ->views_data_alter($data, $field);
  }
  return $data;
}