You are here

public function EntityDefaultViewsController::views_data in Entity API 7

Defines the result for hook_views_data().

File

views/entity.views.inc, line 367
Provide views data for modules making use of the entity CRUD API.

Class

EntityDefaultViewsController
Default controller for generating basic views integration.

Code

public function views_data() {
  $data = array();
  $this->relationships = array();
  if (!empty($this->info['base table'])) {
    $table = $this->info['base table'];

    // Define the base group of this table. Fields that don't
    // have a group defined will go into this field by default.
    $data[$table]['table']['group'] = drupal_ucfirst($this->info['label']);
    $data[$table]['table']['entity type'] = $this->type;

    // If the plural label isn't available, use the regular label.
    $label = isset($this->info['plural label']) ? $this->info['plural label'] : $this->info['label'];
    $data[$table]['table']['base'] = array(
      'field' => $this->info['entity keys']['id'],
      'access query tag' => $this->type . '_access',
      'title' => drupal_ucfirst($label),
      'help' => isset($this->info['description']) ? $this->info['description'] : '',
    );
    $data[$table]['table']['entity type'] = $this->type;
    $data[$table] += $this
      ->schema_fields();

    // Add in any reverse-relationships which have been determined.
    $data += $this->relationships;
  }
  if (!empty($this->info['revision table']) && !empty($this->info['entity keys']['revision'])) {
    $revision_table = $this->info['revision table'];
    $data[$table]['table']['default_relationship'] = array(
      $revision_table => array(
        'table' => $revision_table,
        'field' => $this->info['entity keys']['revision'],
      ),
    );

    // Define the base group of this table. Fields that don't
    // have a group defined will go into this field by default.
    $data[$revision_table]['table']['group'] = drupal_ucfirst($this->info['label']) . ' ' . t('Revisions');
    $data[$revision_table]['table']['entity type'] = $this->type;

    // If the plural label isn't available, use the regular label.
    $label = isset($this->info['plural label']) ? $this->info['plural label'] : $this->info['label'];
    $data[$revision_table]['table']['base'] = array(
      'field' => $this->info['entity keys']['revision'],
      'access query tag' => $this->type . '_access',
      'title' => drupal_ucfirst($label) . ' ' . t('Revisions'),
      'help' => (isset($this->info['description']) ? $this->info['description'] . ' ' : '') . t('Revisions'),
    );
    $data[$revision_table]['table']['entity type'] = $this->type;
    $data[$revision_table] += $this
      ->schema_revision_fields();

    // Add in any reverse-relationships which have been determined.
    $data += $this->relationships;

    // For other base tables, explain how we join.
    $data[$revision_table]['table']['join'] = array(
      // Directly links to base table.
      $table => array(
        'left_field' => $this->info['entity keys']['revision'],
        'field' => $this->info['entity keys']['revision'],
      ),
    );
    $data[$revision_table]['table']['default_relationship'] = array(
      $table => array(
        'table' => $table,
        'field' => $this->info['entity keys']['id'],
      ),
    );
  }
  return $data;
}