class EntityReference_SelectionHandler_Translation_Generic_node in Translated Entity Reference 7
Override for the Node type.
This only exists to workaround core bugs.
Hierarchy
- class \EntityReference_SelectionHandler_Generic implements EntityReference_SelectionHandler
Expanded class hierarchy of EntityReference_SelectionHandler_Translation_Generic_node
File
- plugins/
selection/ EntityReference_SelectionHandler_Translation_Generic.class.php, line 38
View source
class EntityReference_SelectionHandler_Translation_Generic_node extends EntityReference_SelectionHandler_Generic_node {
/**
* Overrides EntityReference_SelectionHandler_Generic_node::entityFieldQueryAlter().
* Adds language filtering logic.
*/
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);
}
}
/**
* Overrides EntityReference_SelectionHandler_Generic::settingsForm().
* 0 = Makes the filtering configurable. Either show all nodes (filtered on
* interface language) or show only those nodes with the same language as the
* referencing (parent) node.
*/
public static function settingsForm($field, $instance) {
$form = parent::settingsForm($field, $instance);
$form['filter']['language'] = array(
'#type' => 'select',
'#title' => t('Language handling'),
'#options' => array(
0 => t('Select all nodes matching with the interface language'),
1 => t('Select only nodes matching the parent\'s language'),
),
'#default_value' => isset($field['settings']['handler_settings']['filter']['language']) ? $field['settings']['handler_settings']['filter']['language'] : 0,
);
return $form;
}
}