You are here

function editableviews_field_views_data_alter in Editable Views 7

Implement hook_field_views_data_alter.

Define the direction of entityreference forward relationships.

Watch carefully: this is called by Field module's hook_views_data() to alter the Views data definition for a single field, either as given by the field module itself with hook_field_views_data(), or by default values. In our case, we're altering entityreference field data defined in entityreference_field_views_data().

File

./editableviews.views.inc, line 147
editableviews.views.inc Contains Views hooks.

Code

function editableviews_field_views_data_alter(&$data, $field, $module) {

  // Bail for anything else.
  if ($module != 'entityreference') {
    return;
  }

  // There will be more than one table (node revisions). But we only care about
  // the real one.
  $table_name = _field_sql_storage_tablename($field);
  $field_name = $field['field_name'] . '_target_id';
  $data[$table_name][$field_name]['relationship']['editableviews_direction'] = 'forward';

  // This is mysteriously missing from Entityreference!
  $data[$table_name][$field_name]['relationship']['field_name'] = $field['field_name'];
}