26
modules/translation/views_handler_argument_node_tnid.inc
Normal file
26
modules/translation/views_handler_argument_node_tnid.inc
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provide node tnid argument handler.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Argument handler to accept a node translation id.
|
||||
*
|
||||
* @ingroup views_argument_handlers
|
||||
*/
|
||||
class views_handler_argument_node_tnid extends views_handler_argument_numeric {
|
||||
/**
|
||||
* Override the behavior of title(). Get the title of the node.
|
||||
*/
|
||||
function title_query() {
|
||||
$titles = array();
|
||||
|
||||
$result = db_query("SELECT n.title FROM {node} n WHERE n.tnid IN (:tnids)", array(':tnids' => $this->value));
|
||||
foreach ($result as $term) {
|
||||
$titles[] = check_plain($term->title);
|
||||
}
|
||||
return $titles;
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_field_node_link_translate.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to present a link node translate.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_node_link_translate extends views_handler_field_node_link {
|
||||
function render_link($data, $values) {
|
||||
// ensure user has access to edit this node.
|
||||
$node = $this->get_value($values);
|
||||
$node->status = 1; // unpublished nodes ignore access control
|
||||
if (empty($node->language) || !translation_supported_type($node->type) || !node_access('view', $node) || !user_access('translate content')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->options['alter']['make_link'] = TRUE;
|
||||
$this->options['alter']['path'] = "node/$node->nid/translate";
|
||||
$this->options['alter']['query'] = drupal_get_destination();
|
||||
|
||||
$text = !empty($this->options['text']) ? $this->options['text'] : t('translate');
|
||||
return $text;
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_field_node_translation_link.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to present a link to the node.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_node_translation_link extends views_handler_field {
|
||||
function construct() {
|
||||
parent::construct();
|
||||
$this->additional_fields['nid'] = 'nid';
|
||||
$this->additional_fields['tnid'] = 'tnid';
|
||||
$this->additional_fields['title'] = 'title';
|
||||
$this->additional_fields['language'] = 'language';
|
||||
}
|
||||
|
||||
function query() {
|
||||
$this->ensure_my_table();
|
||||
$this->add_additional_fields();
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
$value = $this->get_value($values, 'tnid');
|
||||
return $this->render_link($this->sanitize_value($value), $values);
|
||||
}
|
||||
|
||||
function render_link($data, $values) {
|
||||
global $language;
|
||||
|
||||
$tnid = $this->get_value($values, 'tnid');
|
||||
// Only load translations if the node isn't in the current language.
|
||||
if ($this->get_value($values, 'language') != $language->language) {
|
||||
$translations = translation_node_get_translations($tnid);
|
||||
if (isset($translations[$language->language])) {
|
||||
$values->{$this->aliases['nid']} = $translations[$language->language]->nid;
|
||||
$values->{$this->aliases['title']} = $translations[$language->language]->title;
|
||||
}
|
||||
}
|
||||
|
||||
$this->options['alter']['make_link'] = TRUE;
|
||||
$this->options['alter']['path'] = "node/" . $this->get_value($values, 'nid');
|
||||
return $this->get_value($values, 'title');
|
||||
}
|
||||
}
|
45
modules/translation/views_handler_filter_node_tnid.inc
Normal file
45
modules/translation/views_handler_filter_node_tnid.inc
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_filter_node_tnid.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Filter by whether the node is the original translation.
|
||||
*
|
||||
* @ingroup views_filter_handlers
|
||||
*/
|
||||
class views_handler_filter_node_tnid extends views_handler_filter {
|
||||
function admin_summary() { }
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['operator']['default'] = 1;
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide simple boolean operator
|
||||
*/
|
||||
function operator_form(&$form, &$form_state) {
|
||||
$form['operator'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Include untranslated content'),
|
||||
'#default_value' => $this->operator,
|
||||
'#options' => array(
|
||||
1 => t('Yes'),
|
||||
0 => t('No'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function can_expose() { return FALSE; }
|
||||
|
||||
function query() {
|
||||
$table = $this->ensure_my_table();
|
||||
// Select for source translations (tnid = nid). Conditionally, also accept either untranslated nodes (tnid = 0).
|
||||
$this->query->add_where_expression($this->options['group'], "$table.tnid = $table.nid" . ($this->operator ? " OR $table.tnid = 0" : ''));
|
||||
}
|
||||
}
|
22
modules/translation/views_handler_filter_node_tnid_child.inc
Normal file
22
modules/translation/views_handler_filter_node_tnid_child.inc
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_filter_node_tnid_child.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Filter by whether the node is not the original translation.
|
||||
*
|
||||
* @ingroup views_filter_handlers
|
||||
*/
|
||||
class views_handler_filter_node_tnid_child extends views_handler_filter {
|
||||
function admin_summary() { }
|
||||
function operator_form(&$form, &$form_state) { }
|
||||
function can_expose() { return FALSE; }
|
||||
|
||||
function query() {
|
||||
$table = $this->ensure_my_table();
|
||||
$this->query->add_where_expression($this->options['group'], "$table.tnid <> $table.nid AND $table.tnid > 0");
|
||||
}
|
||||
}
|
103
modules/translation/views_handler_relationship_translation.inc
Normal file
103
modules/translation/views_handler_relationship_translation.inc
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_relationship_translation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handles relationships for content translation sets and provides multiple
|
||||
* options.
|
||||
*
|
||||
* @ingroup views_relationship_handlers
|
||||
*/
|
||||
class views_handler_relationship_translation extends views_handler_relationship {
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['language'] = array('default' => 'current');
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a translation selector.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$options = array(
|
||||
'all' => t('All'),
|
||||
'current' => t('Current language'),
|
||||
'default' => t('Default language'),
|
||||
);
|
||||
$options = array_merge($options, locale_language_list());
|
||||
$form['language'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => $options,
|
||||
'#default_value' => $this->options['language'],
|
||||
'#title' => t('Translation option'),
|
||||
'#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.'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to implement a relationship in a query.
|
||||
*/
|
||||
function query() {
|
||||
// Figure out what base table this relationship brings to the party.
|
||||
$table_data = views_fetch_data($this->definition['base']);
|
||||
$base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field'];
|
||||
|
||||
$this->ensure_my_table();
|
||||
|
||||
$def = $this->definition;
|
||||
$def['table'] = $this->definition['base'];
|
||||
$def['field'] = $base_field;
|
||||
$def['left_table'] = $this->table_alias;
|
||||
$def['left_field'] = $this->field;
|
||||
if (!empty($this->options['required'])) {
|
||||
$def['type'] = 'INNER';
|
||||
}
|
||||
|
||||
$def['extra'] = array();
|
||||
if ($this->options['language'] != 'all') {
|
||||
switch ($this->options['language']) {
|
||||
case 'current':
|
||||
$def['extra'][] = array(
|
||||
'field' => 'language',
|
||||
'value' => '***CURRENT_LANGUAGE***',
|
||||
);
|
||||
break;
|
||||
case 'default':
|
||||
$def['extra'][] = array(
|
||||
'field' => 'language',
|
||||
'value' => '***DEFAULT_LANGUAGE***',
|
||||
);
|
||||
break;
|
||||
// Other values will be the language codes.
|
||||
default:
|
||||
$def['extra'][] = array(
|
||||
'field' => 'language',
|
||||
'value' => $this->options['language'],
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($def['join_handler']) && class_exists($def['join_handler'])) {
|
||||
$join = new $def['join_handler'];
|
||||
}
|
||||
else {
|
||||
$join = new views_join();
|
||||
}
|
||||
|
||||
$join->definition = $def;
|
||||
$join->construct();
|
||||
$join->adjusted = TRUE;
|
||||
|
||||
// use a short alias for this:
|
||||
$alias = $def['table'] . '_' . $this->table;
|
||||
|
||||
$this->alias = $this->query->add_relationship($alias, $join, $this->definition['base'], $this->relationship);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user