4 * Handles relationships for content translation sets and provides multiple
7 class views_handler_relationship_translation
extends views_handler_relationship
{
8 function option_definition() {
9 $options = parent
::option_definition();
10 $options['language'] = array('default' => 'current');
16 * Add a translation selector.
18 function options_form(&$form, &$form_state) {
19 parent
::options_form($form, $form_state);
23 'current' => t('Current language'),
24 'default' => t('Default language'),
26 $options = array_merge($options, locale_language_list());
27 $form['language'] = array(
29 '#options' => $options,
30 '#default_value' => $this->options
['language'],
31 '#title' => t('Translation option'),
32 '#description' => t('The translation options allows you to select which translation or translations in a translation set join on. Select "Current language" or "Default language" to join on the translation in the current or default language respectively. Select a specific language to join on a translation in that language. If you select "All", each translation will create a new row, which may appear to cause duplicates.'),
37 * Called to implement a relationship in a query.
40 // Figure out what base table this relationship brings to the party.
41 $table_data = views_fetch_data($this->definition
['base']);
42 $base_field = empty($this->definition
['base field']) ?
$table_data['table']['base']['field'] : $this->definition
['base field'];
44 $this->ensure_my_table();
46 $def = $this->definition
;
47 $def['table'] = $this->definition
['base'];
48 $def['field'] = $base_field;
49 $def['left_table'] = $this->table_alias
;
50 $def['left_field'] = $this->field
;
51 if (!empty($this->options
['required'])) {
52 $def['type'] = 'INNER';
55 $def['extra'] = array();
56 if ($this->options
['language'] != 'all') {
57 switch ($this->options
['language']) {
59 $def['extra'][] = array(
60 'field' => 'language',
61 'value' => '***CURRENT_LANGUAGE***',
65 $def['extra'][] = array(
66 'field' => 'language',
67 'value' => '***DEFAULT_LANGUAGE***',
70 // Other values will be the language codes.
72 $def['extra'][] = array(
73 'field' => 'language',
74 'value' => $this->options
['language'],
80 if (!empty($def['join_handler']) && class_exists($def['join_handler'])) {
81 $join = new
$def['join_handler'];
84 $join = new
views_join();
87 $join->definition
= $def;
89 $join->adjusted
= TRUE
;
91 // use a short alias for this:
92 $alias = $def['table'] .
'_' .
$this->table
;
94 $this->alias
= $this->query
->add_relationship($alias, $join, $this->definition
['base'], $this->relationship
);