| 2 |
// $Id$ |
// $Id$ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Implementation of hook_views_data() |
* Implementation of hook_views_data_alter() |
| 6 |
*/ |
*/ |
| 7 |
|
|
| 8 |
function select_translation_views_data() { |
function select_translation_views_data_alter(&$cache) { |
| 9 |
$data['node']['select_translation'] = array( |
$cache['node']['select_translation'] = array( |
| 10 |
'title' => t('Select translation'), |
'title' => t('Select translation'), |
| 11 |
'help' => t('For all the nodes representing a translation of the same content, only display one of the nodes'), |
'help' => t('For all the nodes representing a translation of the same content, only display one of the nodes'), |
| 12 |
'filter' => array( |
'filter' => array( |
| 17 |
return $data; |
return $data; |
| 18 |
} |
} |
| 19 |
|
|
| 20 |
class select_translation_filter_handler extends views_handler_filter { |
/** |
| 21 |
// Don't display empty space where the operator would be. |
* Implementation of hook_views_handlers |
| 22 |
var $no_operator = TRUE; |
*/ |
| 23 |
|
function select_translation_views_handlers() { |
| 24 |
function option_definition() { |
return array( |
| 25 |
$options = parent::option_definition(); |
'info' => array( |
| 26 |
|
'path' => drupal_get_path('module', 'select_translation'), |
| 27 |
$options['value']['default'] = 'default'; |
), |
| 28 |
|
'handlers' => array( |
| 29 |
return $options; |
'select_translation_filter_handler' => array( |
| 30 |
} |
'parent' => 'views_handler_filter', |
| 31 |
|
), |
| 32 |
function operator_form(&$form, &$form_state) { |
), |
| 33 |
$form['operator'] = array(); |
); |
|
} |
|
|
|
|
|
function value_form(&$form, &$form_state) { |
|
|
$form['value'] = array( |
|
|
'#type' => 'radios', |
|
|
'#title' => t('Select translation selection mode'), |
|
|
'#options' => array( |
|
|
'original' => t('Use current language ; if not available use original language'), |
|
|
'default' => t('Use current language ; if not available use default language ; if not available use original language'), |
|
|
), |
|
|
'#default_value' => $this->value, |
|
|
); |
|
|
} |
|
|
|
|
|
function query() { |
|
|
if ($this->value == 'original') { |
|
|
$this->query->add_where($this->options['group'], " |
|
|
node.tnid = 0 |
|
|
OR node.language = '***CURRENT_LANGUAGE***' |
|
|
OR (node.nid = node.tnid AND |
|
|
0 = (SELECT COUNT(nid) |
|
|
FROM node AS lmfh_node |
|
|
WHERE lmfh_node.language = '***CURRENT_LANGUAGE***' |
|
|
AND lmfh_node.tnid = node.tnid) |
|
|
)"); |
|
|
} else { |
|
|
$default = language_default('language'); |
|
|
$this->query->add_where($this->options['group'], " |
|
|
node.tnid = 0 |
|
|
OR node.language = '***CURRENT_LANGUAGE***' |
|
|
OR (node.language = '$default' |
|
|
AND 0 = (SELECT COUNT(nid) |
|
|
FROM node AS lmfh_node |
|
|
WHERE lmfh_node.language = '***CURRENT_LANGUAGE***' |
|
|
AND lmfh_node.tnid = node.tnid) |
|
|
) |
|
|
OR (node.nid = node.tnid |
|
|
AND 0 = (SELECT COUNT(nid) |
|
|
FROM node AS lmfh_node |
|
|
WHERE lmfh_node.language = '***CURRENT_LANGUAGE***' |
|
|
OR lmfh_node.language = '$default' |
|
|
AND lmfh_node.tnid = node.tnid) |
|
|
) |
|
|
"); |
|
|
} |
|
|
} |
|
| 34 |
} |
} |
| 35 |
|
|