entity_translation_handler_relationship.inc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * @file
  4. * Contains a views plugin for relating entities to translation metadata.
  5. */
  6. /**
  7. * Add a relationship to the entity translation table.
  8. */
  9. class entity_translation_handler_relationship extends views_handler_relationship {
  10. /**
  11. * Add a relationship to the entity_translation table.
  12. */
  13. function query() {
  14. $this->ensure_my_table();
  15. $def = $this->definition;
  16. $def['table'] = 'entity_translation';
  17. $def['field'] = 'entity_id';
  18. $def['left_table'] = $this->table_alias;
  19. $def['type'] = empty($this->options['required']) ? 'LEFT' : 'INNER';
  20. $join = new views_join();
  21. $join->definition = $def;
  22. $join->construct();
  23. $join->adjusted = TRUE;
  24. // Use a short alias for the table.
  25. $alias = $def['table'] . '_' . $this->table;
  26. // We need to add a condition on entity type to the join to avoid getting
  27. // relationships to entities with other types.
  28. $join->extra = array(
  29. array('field' => 'entity_type', 'value' => $def['entity type']),
  30. );
  31. $this->alias = $this->query->add_relationship($alias, $join, 'entity_translation', $this->relationship);
  32. }
  33. }