· 7 years ago · Sep 28, 2018, 12:22 AM
1From 000cb8fd3f2ef56b8b4baf346801c081f483648a Mon Sep 17 00:00:00 2001
2From: Fabian Sorqvist <fabian.sorqvist@gmail.com>
3Date: Mon, 16 Apr 2012 19:26:44 +0200
4Subject: [PATCH] Views integration
5
6---
7 entity_translation.info | 6 +
8 entity_translation.module | 10 +
9 views/entity_translation.views.inc | 227 ++++++++++++++++++++
10 views/entity_translation_handler_field_label.inc | 72 ++++++
11 ...ty_translation_handler_field_translate_link.inc | 96 ++++++++
12 ...tity_translation_handler_filter_entity_type.inc | 30 +++
13 .../entity_translation_handler_filter_language.inc | 27 +++
14 ...anslation_handler_filter_translation_exists.inc | 132 ++++++++++++
15 views/entity_translation_handler_relationship.inc | 32 +++
16 9 files changed, 632 insertions(+), 0 deletions(-)
17 create mode 100644 views/entity_translation.views.inc
18 create mode 100644 views/entity_translation_handler_field_label.inc
19 create mode 100644 views/entity_translation_handler_field_translate_link.inc
20 create mode 100644 views/entity_translation_handler_filter_entity_type.inc
21 create mode 100644 views/entity_translation_handler_filter_language.inc
22 create mode 100644 views/entity_translation_handler_filter_translation_exists.inc
23 create mode 100644 views/entity_translation_handler_relationship.inc
24
25diff --git a/entity_translation.info b/entity_translation.info
26index 8fca343..a7dbc74 100644
27--- a/entity_translation.info
28+++ b/entity_translation.info
29@@ -7,3 +7,9 @@ dependencies[] = locale
30 files[] = includes/translation.handler.inc
31 files[] = includes/translation.handler.node.inc
32 files[] = tests/entity_translation.test
33+files[] = views/entity_translation_handler_relationship.inc
34+files[] = views/entity_translation_handler_field_translate_link.inc
35+files[] = views/entity_translation_handler_field_label.inc
36+files[] = views/entity_translation_handler_filter_entity_type.inc
37+files[] = views/entity_translation_handler_filter_language.inc
38+files[] = views/entity_translation_handler_filter_translation_exists.inc
39diff --git a/entity_translation.module b/entity_translation.module
40index 467c110..e4087be 100644
41--- a/entity_translation.module
42+++ b/entity_translation.module
43@@ -114,6 +114,16 @@ function entity_translation_entity_info_alter(&$entity_info) {
44 }
45
46 /**
47+ * Implements hook_views_api().
48+ */
49+function entity_translation_views_api() {
50+ return array(
51+ 'api' => 3,
52+ 'path' => drupal_get_path('module', 'entity_translation') . '/views',
53+ );
54+}
55+
56+/**
57 * Helper function to determine if the given entity type is translatable.
58 */
59 function entity_translation_enabled($entity_type, $skip_handler = FALSE) {
60diff --git a/views/entity_translation.views.inc b/views/entity_translation.views.inc
61new file mode 100644
62index 0000000..8a59f2f
63--- /dev/null
64+++ b/views/entity_translation.views.inc
65@@ -0,0 +1,227 @@
66+<?php
67+/**
68+ * @file
69+ *
70+ * Provide views data and handlers for entity_translation.
71+ */
72+
73+/**
74+ * Implements hook_views_data().
75+ */
76+function entity_translation_views_data() {
77+ $data = array();
78+ $data['entity_translation']['table']['group'] = t('Entity translation');
79+ // Advertise this table as a possible base table.
80+ $data['entity_translation']['table']['base'] = array(
81+ 'field' => 'entity_id',
82+ 'title' => t('Entity translation'),
83+ 'help' => t('Information about a translation of an entity.'),
84+ );
85+ $data['entity_translation']['entity_id'] = array(
86+ 'title' => t('Entity id'),
87+ 'help' => t('The entity id.'),
88+ 'field' => array(
89+ 'handler' => 'views_handler_field_numeric',
90+ 'click sortable' => TRUE,
91+ ),
92+ 'argument' => array(
93+ 'handler' => 'views_handler_argument_numeric',
94+ 'numeric' => TRUE,
95+ 'validate type' => 'entity_id',
96+ ),
97+ 'filter' => array(
98+ 'handler' => 'views_handler_filter_numeric',
99+ ),
100+ 'sort' => array(
101+ 'handler' => 'views_handler_sort',
102+ ),
103+ );
104+ $data['entity_translation']['entity_type'] = array(
105+ 'title' => t('Entity type'),
106+ 'help' => t('The entity type.'),
107+ 'field' => array(
108+ 'handler' => 'views_handler_field',
109+ 'click sortable' => TRUE,
110+ ),
111+ 'argument' => array(
112+ 'handler' => 'views_handler_argument_string',
113+ 'numeric' => FALSE,
114+ 'validate type' => 'entity_type',
115+ ),
116+ 'filter' => array(
117+ 'handler' => 'entity_translation_handler_filter_entity_type',
118+ ),
119+ 'sort' => array(
120+ 'handler' => 'views_handler_sort',
121+ ),
122+ );
123+ $data['entity_translation']['language'] = array(
124+ 'title' => t('Language'),
125+ 'help' => t('The language of this translation.'),
126+ 'field' => array(
127+ 'handler' => 'views_handler_field_locale_language',
128+ 'click sortable' => TRUE,
129+ ),
130+ 'argument' => array(
131+ 'handler' => 'views_handler_argument_locale_language',
132+ 'numeric' => FALSE,
133+ 'validate type' => 'language',
134+ ),
135+ 'filter' => array(
136+ 'handler' => 'entity_translation_handler_filter_language',
137+ 'allow empty' => TRUE,
138+ ),
139+ 'sort' => array(
140+ 'handler' => 'views_handler_sort',
141+ ),
142+ );
143+ $data['entity_translation']['source'] = array(
144+ 'title' => t('Source'),
145+ 'help' => t('The source language.'),
146+ 'field' => array(
147+ 'handler' => 'views_handler_field_locale_language',
148+ 'click sortable' => TRUE,
149+ ),
150+ 'argument' => array(
151+ 'handler' => 'views_handler_argument_locale_language',
152+ 'name field' => 'title',
153+ 'numeric' => FALSE,
154+ 'validate type' => 'string',
155+ ),
156+ 'filter' => array(
157+ 'handler' => 'entity_translation_handler_filter_language',
158+ 'allow empty' => TRUE,
159+ ),
160+ 'sort' => array(
161+ 'handler' => 'views_handler_sort',
162+ ),
163+ );
164+ $data['entity_translation']['status'] = array(
165+ 'title' => t('Translation status'),
166+ 'help' => t('The status of this translation.'),
167+ 'field' => array(
168+ 'handler' => 'views_handler_field_boolean',
169+ 'click sortable' => TRUE,
170+ ),
171+ 'argument' => array(
172+ 'handler' => 'views_handler_argument_numeric',
173+ 'numeric' => TRUE,
174+ 'validate type' => 'boolean',
175+ ),
176+ 'filter' => array(
177+ 'handler' => 'views_handler_filter_boolean_operator',
178+ ),
179+ 'sort' => array(
180+ 'handler' => 'views_handler_sort',
181+ ),
182+ );
183+ $data['entity_translation']['translate'] = array(
184+ 'title' => t('Needs update'),
185+ 'help' => t('Indicates if the translation needs to be updated.'),
186+ 'field' => array(
187+ 'handler' => 'views_handler_field_boolean',
188+ 'click sortable' => TRUE,
189+ ),
190+ 'argument' => array(
191+ 'handler' => 'views_handler_argument_numeric',
192+ 'name field' => 'title',
193+ 'numeric' => TRUE,
194+ 'validate type' => 'boolean',
195+ ),
196+ 'filter' => array(
197+ 'handler' => 'views_handler_filter_boolean_operator',
198+ ),
199+ 'sort' => array(
200+ 'handler' => 'views_handler_sort',
201+ ),
202+ );
203+ $data['entity_translation']['created'] = array(
204+ 'title' => t('Created'),
205+ 'help' => t('Created date.'),
206+ 'field' => array(
207+ 'handler' => 'views_handler_field_date',
208+ 'click sortable' => TRUE,
209+ ),
210+ 'argument' => array(
211+ 'handler' => 'views_handler_argument_date',
212+ 'numeric' => FALSE,
213+ 'validate type' => 'date',
214+ ),
215+ 'filter' => array(
216+ 'handler' => 'views_handler_filter_date',
217+ ),
218+ 'sort' => array(
219+ 'handler' => 'views_handler_sort_date',
220+ ),
221+ );
222+ $data['entity_translation']['changed'] = array(
223+ 'title' => t('Changed'),
224+ 'help' => t('Changed date.'),
225+ 'field' => array(
226+ 'handler' => 'views_handler_field_date',
227+ 'click sortable' => TRUE,
228+ ),
229+ 'argument' => array(
230+ 'handler' => 'views_handler_argument_date',
231+ 'numeric' => FALSE,
232+ 'validate type' => 'date',
233+ ),
234+ 'filter' => array(
235+ 'handler' => 'views_handler_filter_date',
236+ ),
237+ 'sort' => array(
238+ 'handler' => 'views_handler_sort_date',
239+ ),
240+ );
241+ $data['entity_translation']['translate_link'] = array(
242+ 'title' => t('Translate link'),
243+ 'help' => t('Link to translation overview page.'),
244+ 'field' => array(
245+ 'handler' => 'entity_translation_handler_field_translate_link',
246+ ),
247+ );
248+ $data['entity_translation']['translation_exists'] = array(
249+ 'title' => t('Translation exists'),
250+ 'help' => t('Link to translation overview page.'),
251+ 'filter' => array(
252+ 'handler' => 'entity_translation_handler_filter_translation_exists',
253+ ),
254+ );
255+ $data['entity_translation']['label'] = array(
256+ 'title' => t('Label'),
257+ 'help' => t('The label of the entity.'),
258+ 'field' => array(
259+ 'handler' => 'entity_translation_handler_field_label',
260+ ),
261+ );
262+ return $data;
263+}
264+
265+/**
266+ * Implements hook_views_data_alter().
267+ *
268+ * Add entity translation information to the various entity tables.
269+ */
270+function entity_translation_views_data_alter(&$data) {
271+ foreach (entity_get_info() as $type => $info) {
272+ if ($info['fieldable'] && isset($data[$info['base table']])) {
273+ $table = &$data[$info['base table']];
274+ $table['entity_translations'] = array(
275+ 'title' => t('Entity translation: translations'),
276+ 'help' => t('Translation information.'),
277+ 'relationship' => array(
278+ 'label' => t('Translations'),
279+ 'base' => 'entity_translation',
280+ 'base field' => 'entity_id',
281+ 'relationship field' => $info['entity keys']['id'],
282+ 'handler' => 'entity_translation_handler_relationship',
283+ // We add our information here in the definition,
284+ // so we can copy it later.
285+ 'left_table' => $info['base table'],
286+ 'left_field' => $info['entity keys']['id'],
287+ 'entity type' => $type,
288+ ),
289+ );
290+ }
291+ }
292+}
293diff --git a/views/entity_translation_handler_field_label.inc b/views/entity_translation_handler_field_label.inc
294new file mode 100644
295index 0000000..82a08bc
296--- /dev/null
297+++ b/views/entity_translation_handler_field_label.inc
298@@ -0,0 +1,72 @@
299+<?php
300+/**
301+ * @file
302+ * This file contains a label field handler for entity translation.
303+ */
304+
305+/**
306+ * This handler shows the entity label for entities in the entity_translation table.
307+ */
308+class entity_translation_handler_field_label extends views_handler_field {
309+ function construct() {
310+ parent::construct();
311+ $this->additional_fields['entity_id'] = 'entity_id';
312+ $this->additional_fields['entity_type'] = 'entity_type';
313+ }
314+
315+ function query() {
316+ $this->ensure_my_table();
317+ $this->add_additional_fields();
318+ }
319+ /**
320+ * Add a 'link to entity' option definition.
321+ * @see views_handler_field::option:definition()
322+ */
323+ function option_definition() {
324+ $options = parent::option_definition();
325+ $options['link_to_entity'] = array('default' => '', 'translatable' => FALSE);
326+ return $options;
327+ }
328+
329+ /**
330+ * Add a 'link to entity' option.
331+ * @see views_handler_field::options_form()
332+ */
333+ function options_form(&$form, &$form_state) {
334+ parent::options_form($form, $form_state);
335+ $form['link_to_entity'] = array(
336+ '#title' => t('Link this field to it\'s entity'),
337+ '#type' => 'checkbox',
338+ '#default_value' => $this->options['link_to_entity']
339+ );
340+ }
341+
342+ /**
343+ * Load all entities, so that we can get the label.
344+ */
345+ function post_execute(&$values) {
346+ $ids = array();
347+ $ids_by_type = array();
348+ foreach ($values as $row) {
349+ $ids_by_type[$this->get_value($row, 'entity_type')][] = $this->get_value($row, 'entity_id');
350+ }
351+ foreach ($ids_by_type as $type => $ids) {
352+ $this->entities[$type] = entity_load($type, $ids);
353+ }
354+ }
355+
356+ function render(&$values) {
357+ $entity_type = $this->get_value($values, 'entity_type');
358+ $entity_id = $this->get_value($values, 'entity_id');
359+ $entity = $this->entities[$entity_type][$entity_id];
360+ // We could also use entity_label(), but since this we might want to let
361+ // the handler decide what's best to show.
362+ $handler = entity_translation_get_handler($entity_type, $entity);
363+ $label = $handler->getLabel();
364+ if ($this->options['link_to_entity']) {
365+ $this->options['alter']['make_link'] = TRUE;
366+ $this->options['alter']['path'] = $handler->getViewPath();
367+ }
368+ return $label;
369+ }
370+}
371diff --git a/views/entity_translation_handler_field_translate_link.inc b/views/entity_translation_handler_field_translate_link.inc
372new file mode 100644
373index 0000000..52985f9
374--- /dev/null
375+++ b/views/entity_translation_handler_field_translate_link.inc
376@@ -0,0 +1,96 @@
377+<?php
378+/**
379+ * @file
380+ * Translate link plugin.
381+ */
382+
383+/**
384+ * This handler adds translate link for all translatable entities.
385+ */
386+class entity_translation_handler_field_translate_link extends views_handler_field {
387+
388+ function construct() {
389+ parent::construct();
390+ $this->additional_fields['entity_id'] = 'entity_id';
391+ $this->additional_fields['entity_type'] = 'entity_type';
392+ $this->additional_fields['language'] = 'language';
393+ }
394+
395+ /**
396+ * Add required additional fields.
397+ */
398+ function query() {
399+ $this->ensure_my_table();
400+ $this->add_additional_fields();
401+ }
402+
403+ /**
404+ * Add the text option.
405+ * @see views_handler_field::option_definition()
406+ */
407+ function option_definition() {
408+ $options = parent::option_definition();
409+ $options['text'] = array('default' => '', 'translatable' => TRUE);
410+ return $options;
411+ }
412+ /**
413+ * Add the option to set the title of the translate link.
414+ * @see views_handler_field::options_form()
415+ */
416+ function options_form(&$form, &$form_state) {
417+ $form['text'] = array(
418+ '#type' => 'textfield',
419+ '#title' => t('Text to display'),
420+ '#default_value' => $this->options['text'],
421+ );
422+ parent::options_form($form, $form_state);
423+
424+ // The path is set by render_link function so don't allow setting it.
425+ $form['alter']['path'] = array('#access' => FALSE);
426+ $form['alter']['external'] = array('#access' => FALSE);
427+ }
428+
429+ /**
430+ * Load all entities based on the data we have.
431+ */
432+ function post_execute(&$values) {
433+ $ids = array();
434+ $ids_by_type = array();
435+ foreach ($values as $row) {
436+ $ids_by_type[$this->get_value($row, 'entity_type')][] = $this->get_value($row, 'entity_id');
437+ }
438+ foreach ($ids_by_type as $type => $ids) {
439+ $this->entities[$type] = entity_load($type, $ids);
440+ }
441+ }
442+
443+ /**
444+ * @see views_handler_field::render()
445+ */
446+ function render($values) {
447+ $type = $this->get_value($values, 'entity_type');
448+ $entity_id = $this->get_value($values, 'entity_id');
449+ $language = $this->get_value($values, 'language');
450+ $entity = $this->entities[$type][$entity_id];
451+ return $this->render_link($type, $entity_id, $language);
452+ }
453+
454+ /**
455+ * Render the link to the translation overview page of the entity.
456+ */
457+ function render_link($entity_type, $entity_id, $language) {
458+ if (!entity_translation_enabled($entity_type) || !entity_translation_tab_access($entity_type) || $language == 'und') {
459+ return;
460+ }
461+ // We use the entity info here to avoid having to call entity_load()
462+ // for all entities.
463+ $info = entity_get_info($entity_type);
464+ $path = $info['translation']['entity_translation']['base path'];
465+ $path = str_replace($info['translation']['entity_translation']['path wildcard'], $entity_id, $path);
466+ $this->options['alter']['make_link'] = TRUE;
467+ $this->options['alter']['path'] = $path . '/translate';
468+ $this->options['alter']['query'] = drupal_get_destination();
469+ $text = !empty($this->options['text']) ? $this->options['text'] : t('translate');
470+ return $text;
471+ }
472+}
473diff --git a/views/entity_translation_handler_filter_entity_type.inc b/views/entity_translation_handler_filter_entity_type.inc
474new file mode 100644
475index 0000000..5c2d8ef
476--- /dev/null
477+++ b/views/entity_translation_handler_filter_entity_type.inc
478@@ -0,0 +1,30 @@
479+<?php
480+/**
481+ * @file
482+ * Contains an entity type filter handler.
483+ */
484+
485+/**
486+ * handler shows all available entity types
487+ * that are enabled for entity translation as options.
488+ */
489+class entity_translation_handler_filter_entity_type extends views_handler_filter_in_operator {
490+
491+ /**
492+ * Show all entity types that are enabled for entity translation as options.
493+ */
494+ function get_value_options() {
495+ if (!isset($this->value_options)) {
496+ $this->value_title = t('Entity type');
497+ $allowed_types_options = variable_get('entity_translation_entity_types');
498+ $allowed_types = array();
499+ $entity_info = entity_get_info();
500+ foreach ($allowed_types_options as $key => $allowed) {
501+ if ($allowed) {
502+ $allowed_types[$key] = $entity_info[$key]['label'];
503+ }
504+ }
505+ $this->value_options = $allowed_types;
506+ }
507+ }
508+}
509diff --git a/views/entity_translation_handler_filter_language.inc b/views/entity_translation_handler_filter_language.inc
510new file mode 100644
511index 0000000..7e4b8db
512--- /dev/null
513+++ b/views/entity_translation_handler_filter_language.inc
514@@ -0,0 +1,27 @@
515+<?php
516+/**
517+ * @file
518+ * Contains a language filter handler.
519+ */
520+
521+/**
522+ * Extends the locale language filter in order for it to work
523+ * with the entity translation table structure.
524+ */
525+class entity_translation_handler_filter_language extends views_handler_filter_locale_language {
526+
527+ /**
528+ * Override the default behaviour, insert an empty string instead of NULL.
529+ */
530+ function op_empty() {
531+ $this->ensure_my_table();
532+ if ($this->operator == 'empty') {
533+ $operator = "=";
534+ }
535+ else {
536+ $operator = "<>";
537+ }
538+
539+ $this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field", '', $operator);
540+ }
541+}
542diff --git a/views/entity_translation_handler_filter_translation_exists.inc b/views/entity_translation_handler_filter_translation_exists.inc
543new file mode 100644
544index 0000000..141008c
545--- /dev/null
546+++ b/views/entity_translation_handler_filter_translation_exists.inc
547@@ -0,0 +1,132 @@
548+<?php
549+/**
550+ * @file
551+ * Contains an entity type filter handler.
552+ */
553+
554+/**
555+ * This handler determines if a translation exists for a particular translation.
556+ */
557+class entity_translation_handler_filter_translation_exists extends views_handler_filter_locale_language {
558+
559+ /**
560+ * Add a 'entity_type' option definition.
561+ * @see views_handler_field::option:definition()
562+ */
563+ function option_definition() {
564+ $options = parent::option_definition();
565+ $options['entity_type'] = array('default' => '', 'translatable' => FALSE);
566+ $options['use_filter'] = array('default' => '', 'translatable' => FALSE);
567+ $options['filter'] = array('default' => '', 'translatable' => FALSE);
568+ return $options;
569+ }
570+
571+ /**
572+ * Override the default title for the operators.
573+ */
574+ function operators() {
575+ $operators = parent::operators();
576+ $operators['in']['title'] = t('Translation exists');
577+ $operators['not in']['title'] = t('Translation doesn\'t exist');
578+ return $operators;
579+ }
580+
581+ /**
582+ * Add option for setting entity type either directly or through a filter.
583+ * @see views_handler_field::options_form()
584+ */
585+ function options_form(&$form, &$form_state) {
586+ parent::options_form($form, $form_state);
587+ $filters = $this->get_entity_type_filters();
588+ if (!empty($filters)) {
589+ $form['use_filter'] = array(
590+ '#type' => 'checkbox',
591+ '#title' => t('Use an entity type filter.'),
592+ '#default_value' => $this->options['use_filter'],
593+ );
594+ $form['filter'] = array(
595+ '#type' => 'select',
596+ '#title' => t('Filter'),
597+ '#options' => $filters,
598+ '#dependency' => array(
599+ 'edit-options-use-filter' => array(1)
600+ ),
601+ '#default_value' => $this->options['filter'],
602+ );
603+ }
604+ $form['entity_type'] = array(
605+ '#title' => t('Entity type'),
606+ '#type' => 'select',
607+ '#options' => $this->get_allowed_types(),
608+ '#dependency' => array(
609+ 'edit-options-use-filter' => array(0)
610+ ),
611+ '#default_value' => $this->options['entity_type'],
612+ '#description' => t('You have to filter on a particular entity type when you use this filter'),
613+ );
614+ }
615+
616+ /**
617+ * Get all available entity type filters that can be used to build the query.
618+ */
619+ function get_entity_type_filters() {
620+ // We need to build the query to know about the available fields.
621+ $this->view->build();
622+ $filters = array();
623+ foreach ($this->view->filter as $key => $filter) {
624+ // Break if we encounter our filter, the filter must be before this one.
625+ if ($filter == $this) {
626+ break;
627+ }
628+ if ($filter instanceof entity_translation_handler_filter_entity_type && count($filter->value) == 1 && empty($filter->options['expose']['multiple'])) {
629+ $filters[$key] = $filter->value_title;
630+ }
631+ }
632+ return $filters;
633+ }
634+
635+ /**
636+ * Get entity types managed by entity translation.
637+ */
638+ function get_allowed_types() {
639+ $allowed_types_options = variable_get('entity_translation_entity_types');
640+ $allowed_types = array();
641+ $entity_info = entity_get_info();
642+ foreach ($allowed_types_options as $key => $allowed) {
643+ if ($allowed) {
644+ $allowed_types[$key] = $entity_info[$key]['label'];
645+ }
646+ }
647+ return $allowed_types;
648+ }
649+
650+ /**
651+ * Override the default behaviour of the handler.
652+ */
653+ function query() {
654+ $this->ensure_my_table();
655+ // We need a subquery to determine not in.
656+ if ($this->operator == 'not in') {
657+ $entity_type = 'node';
658+ if ($this->options['use_filter'] && isset($this->view->filter[$this->options['filter']])) {
659+ $filter = $this->view->filter[$this->options['filter']];
660+ $entity_type = current($filter->value);
661+ }
662+ else {
663+ $this->query->add_where($this->options['group'], "$this->table_alias.entity_type", $this->options['entity_type'], '=');
664+ $entity_type = $this->options['entity_type'];
665+ }
666+ $query = db_select('entity_translation', 'es')
667+ ->condition('entity_type', $entity_type)
668+ ->condition('language', $this->value);
669+ $query->addField('es', 'entity_id');
670+ $this->query->add_where($this->options['group'], "$this->table_alias.entity_id", $query, $this->operator);
671+ }
672+ // We can determine if a translation exists without a subquery.
673+ else {
674+ $value = array_keys($this->value);
675+ $this->query->add_where($this->options['group'], "$this->table_alias.source", '', '<>');
676+ $this->query->add_where($this->options['group'], "$this->table_alias.language", array_values($this->value), $this->operator);
677+ }
678+ }
679+}
680diff --git a/views/entity_translation_handler_relationship.inc b/views/entity_translation_handler_relationship.inc
681new file mode 100644
682index 0000000..52da2b5
683--- /dev/null
684+++ b/views/entity_translation_handler_relationship.inc
685@@ -0,0 +1,32 @@
686+<?php
687+/**
688+ * @file
689+ * Contains the relationship plugin for relating entities to translation metadata.
690+ */
691+
692+/**
693+ * Add a relationship to the entity translation table.
694+ */
695+class entity_translation_handler_relationship extends views_handler_relationship {
696+
697+ /**
698+ * Add a relationship to the entity_translation table.
699+ */
700+ function query() {
701+ $this->ensure_my_table();
702+ $def = $this->definition;
703+ $def['table'] = 'entity_translation';
704+ $def['field'] = 'entity_id';
705+ $def['type'] = empty($this->options['required']) ? 'LEFT' : 'INNER';
706+ $join = new views_join();
707+ $join->definition = $def;
708+ $join->construct();
709+ $join->adjusted = TRUE;
710+ // use a short alias for the table.
711+ $alias = $def['table'] . '_' . $this->table;
712+ // We need to add a condition on entity type to the join
713+ // to avoid getting relationships to entities with other types.
714+ $join->extra = "$alias.entity_type = '{$def['entity type']}'";
715+ $this->alias = $this->query->add_relationship($alias, $join, 'entity_translation', $this->relationship);
716+ }
717+}
718--
7191.7.5.4