You are here

function entity_translation_handler_relationship::query in Entity Translation 7

Add a relationship to the entity_translation table.

Overrides views_handler_relationship::query

File

views/entity_translation_handler_relationship.inc, line 16
Contains a views plugin for relating entities to translation metadata.

Class

entity_translation_handler_relationship
Add a relationship to the entity translation table.

Code

function query() {
  $this
    ->ensure_my_table();
  $def = $this->definition;
  $def['table'] = 'entity_translation';
  $def['field'] = 'entity_id';
  $def['left_table'] = $this->table_alias;
  $def['type'] = empty($this->options['required']) ? 'LEFT' : 'INNER';
  $join = new views_join();
  $join->definition = $def;
  $join
    ->construct();
  $join->adjusted = TRUE;

  // Use a short alias for the table.
  $alias = $def['table'] . '_' . $this->table;

  // We need to add a condition on entity type to the join to avoid getting
  // relationships to entities with other types.
  $join->extra = array(
    array(
      'field' => 'entity_type',
      'value' => $def['entity type'],
    ),
  );
  $this->alias = $this->query
    ->add_relationship($alias, $join, 'entity_translation', $this->relationship);
}