You are here

function blockreference_field_views_data in Block reference 7

Implements hook_field_views_data().

In addition to the default field information we add the relationship for views to connect back to the block table.

File

./blockreference.module, line 847
Defines a field type for referencing a block from a node.

Code

function blockreference_field_views_data($field) {

  // No module_load_include(): this hook is invoked from
  // views/modules/field.views.inc, which is where that function is defined.
  $data = field_views_field_default_views_data($field);
  $key = key($field['storage']['details']);
  $storage = $field['storage']['details'][$key];
  foreach ($storage as $age => $table_data) {
    $table = key($table_data);
    $columns = current($table_data);
    $id_column = $columns['bid'];
    if (isset($data[$table])) {
      $data[$table][$id_column]['relationship'] = array(
        'base' => 'block',
        'field' => 'bid',
        'base field' => 'bid',
        'label' => $field['field_name'],
      );
    }
  }
  return $data;
}