You are here

public function EntityReference_SelectionHandler_Translation_Generic_node::entityFieldQueryAlter in Translated Entity Reference 7

Overrides EntityReference_SelectionHandler_Generic_node::entityFieldQueryAlter(). Adds language filtering logic.

Overrides EntityReference_SelectionHandler_Generic_node::entityFieldQueryAlter

File

plugins/selection/EntityReference_SelectionHandler_Translation_Generic.class.php, line 43

Class

EntityReference_SelectionHandler_Translation_Generic_node
Override for the Node type.

Code

public function entityFieldQueryAlter(SelectQueryInterface $query) {
  parent::entityFieldQueryAlter($query);
  $base_table = $this
    ->ensureBaseTable($query);
  $entity_info = entity_get_info($this->field['settings']['target_type']);
  if ($this->field['settings']['handler_settings']['filter']['language'] == 1 && $entity_info['translation']['locale'] == TRUE) {
    $node_language = i18n_node_i18n_context_language();
    if (isset($node_language->language) && !is_null($node_language->language)) {
      $query
        ->condition("{$base_table}.language", $node_language->language);
    }
  }
  else {
    global $language;
    $query
      ->condition("{$base_table}.language", $language->language);
  }
}