You are here

function entity_views_table_definition in Entity API 7

Helper function for getting data selection based entity Views table definitions.

This creates extra tables for each entity type that are not associated with a query plugin (and thus are not base tables) and just rely on the entities to retrieve the displayed data. To obtain the entities corresponding to a certain result set, the field handlers defined on the table use a generic interface defined for query plugins that are based on entity handling, and which is described in the entity_views_example_query class.

These tables are called "data selection tables".

Other modules providing Views integration with new query plugins that are based on entities can then use these tables as a base for their own tables (by directly using this method and modifying the returned table) and/or by specifying relationships to them. The tables returned here already specify relationships to each other wherever an entity contains a reference to another (e.g., the node author constructs a relationship from nodes to users).

As filtering and other query manipulation is potentially more plugin-specific than the display, only field handlers and relationships are provided with these tables. By providing a add_selector_orderby() method, the query plugin can, however, support click-sorting for the field handlers in these tables.

For a detailed discussion see http://drupal.org/node/1266036

For example use see the Search API views module in the Search API project: http://drupal.org/project/search_api

Parameters

$type: The entity type whose table definition should be returned.

$exclude: Whether properties already exposed as 'entity views field' should be excluded. Defaults to TRUE, as they are available for all views tables for the entity type anyways.

Return value

array An array containing the data selection Views table definition for the entity type.

See also

entity_views_field_definition()

1 call to entity_views_table_definition()
entity_views_data in views/entity.views.inc
Implements hook_views_data().

File

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

Code

function entity_views_table_definition($type, $exclude = TRUE) {

  // As other modules might want to copy these tables as a base for their own
  // Views integration, we statically cache the tables to save some time.
  $tables =& drupal_static(__FUNCTION__, array());
  if (!isset($tables[$type])) {

    // Work-a-round to fix updating, see http://drupal.org/node/1330874.
    // Views data might be rebuilt on update.php before the registry is rebuilt,
    // thus the class cannot be auto-loaded.
    if (!class_exists('EntityFieldHandlerHelper')) {
      module_load_include('inc', 'entity', 'views/handlers/entity_views_field_handler_helper');
    }
    $info = entity_get_info($type);
    $tables[$type]['table'] = array(
      'group' => $info['label'],
      'entity type' => $type,
    );
    foreach (entity_get_all_property_info($type) as $key => $property) {
      if (!$exclude || empty($property['entity views field'])) {
        entity_views_field_definition($key, $property, $tables[$type]);
      }
    }
  }
  return $tables[$type];
}