--- a/views/entity_translation_handler_relationship.inc 2013-01-15 10:19:53.715077050 +0100 +++ b/views/entity_translation_handler_relationship.inc 2013-01-15 10:23:42.292210507 +0100 @@ -9,6 +9,36 @@ */ class entity_translation_handler_relationship extends views_handler_relationship { + function option_definition() { + $options = parent::option_definition(); + + $options['language'] = array( + 'default' => '***CURRENT_LANGUAGE***', + ); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + $languages = array( + '' => t('- Any -'), + '***CURRENT_LANGUAGE***' => t("Current user's language"), + '***DEFAULT_LANGUAGE***' => t("Default site language"), + LANGUAGE_NONE => t('Language neutral'), + ); + if (module_exists('locale')) { + $languages = array_merge($languages, locale_language_list()); + } + $form['language'] = array( + '#type' => 'select', + '#title' => t('Language'), + '#options' => $languages, + '#default_value' => $this->options['language'], + '#description' => t('Select the language to display this field in') + ); + } + /** * Add a relationship to the entity_translation table. */ @@ -26,7 +56,10 @@ $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 = "$alias.entity_type = '{$def['entity type']}'"; + $join->extra[] = array('field' => 'entity_type', 'value' => $def['entity type']); + if (!empty($this->options['language'])) { + $join->extra[] = array('field' => 'language', 'value' => $this->options['language']); + } $this->alias = $this->query->add_relationship($alias, $join, 'entity_translation', $this->relationship); } }