In a multi language site I use translated taxonomy terms (i18n) selected in a node field 'reference to term' and shown in a view with a term filter.
This works in a view with a normal exposed filter and with better exposed filter, the translated terms are shown as filter in the corresponding language.
---
Then I installed Views Filters Selective.
With the exposed filter 'term(select)' the filtering works fine (without translation of the term) in the default language.
If 'term(translated)(select)' is used as an exposed filter there is an error: 'No valid values found in filter', and the ajax error:
An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /en/admin/structure/views/view/arrangementen/preview/page/ajax
StatusText: Service unavailable (with message)
ResponseText: PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_data_field_provincie.field_provincie_tid_i18n' in 'field list': SELECT DISTINCT field_data_field_provincie.field_provincie_tid_i18n AS field_data_field_provincie_field_provincie_tid_i18n
FROM
{node} node
LEFT JOIN {field_data_field_provincie} field_data_field_provincie ON node.nid = field_data_field_provincie.entity_id AND (field_data_field_provincie.entity_type = :views_join_condition_0 AND field_data_field_provincie.deleted = :views_join_condition_1)
WHERE (( (node.nid IN (:oids_0, :oids_1, :oids_2)) )); Array
(
[:views_join_condition_0] => node
[:views_join_condition_1] => 0
[:oids_0] => 358
[:oids_1] => 357
[:oids_2] => 332
)
in _views_filter_selective_query() (line 85 of /home/public_html/drupal/sites/countryholidaysholland.com/modules/views_hacks/views_filters_selective/views_filters_selective.module).
Looks like selective filtering is not working with translated terms (18n). Is there a way to make this work?
Comment | File | Size | Author |
---|---|---|---|
#6 | filter.png | 588.05 KB | cmseasy |
#6 | labels.png | 463.71 KB | cmseasy |
#4 | views_hacks-2009362.patch | 3.8 KB | jonhattan |
#2 | views_hacks-2009362.patch | 2.16 KB | jonhattan |
Comments
Comment #1
metastate CreditAttribution: metastate commentedI couldn't get Views Selective Exposed Filters to work with Views Translation either. Even though there is a filter option for "Content: Fieldname (field_fieldname) (translated) (selective)" it doesn't output anything in the View and I get the same errors as mentioned above. The SQL error when I load the view is line 81 for me:
PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column ...
... in _views_filter_selective_query() (line 81 of .../sites/all/modules/views_hacks/views_filters_selective/views_filters_selective.module)
Internationalizations Views - https://drupal.org/project/i18nviews - is still in development though. And not sure about getting different filters to work together like this. Would be great though! But for now I have left the exposed filters in the default language so I can make use of the selective filter.
Comment #2
jonhattanI also hit this. Patched!
Comment #3
cmseasy CreditAttribution: cmseasy commentedThanks for the patch and the help to solve this issue.
With patch #2 the error in my view is not gone. Cleared cache: no effect. The exposed filter is a content field (node term reference). Do I need a relationship to a term? I tried that with no effect....
Comment #4
jonhattanSorry I missed a file when generating previous patch. Check this one.
Comment #5
cmseasy CreditAttribution: cmseasy commentedHi, thanks for patch #4, it worked. The selective filters are correct with the selected languages and the correct languages are shown (translated taxonomy terms).
There are two items remaining.
When the selective filter gives an empty result in the filter, the label of the filter is viewable. A label with no filters has no function. The label should not shown as the selective filter is empty.
When selecting a selective/i18n filter item and hitting the submit button, all the selective/i18n items are gone and one button per label is leftover with the text 'Actual values will be available at run-time'. The view give an empty result. You cannot filter.
Filtering with a non-selective/i18n button gives a good result.
I will attache some images.
Comment #6
cmseasy CreditAttribution: cmseasy commentedThe images
Comment #7
metastate CreditAttribution: metastate commentedThanks for the fix in #4. This gets the initial view to load properly - with both selective filter working and translations available. But when I submit an exposed filter, I get an empty view and each exposed filter now just says "Actual values will be available at run-time." (Same problem cmseasy mentions.)
Not sure if our configurations are different. This happens whether I have only one translated/selective filter added to the view or more than one. I am using both content and fields for my exposed filters:
Content: Fieldname1 (field_fieldname1) (translated) (selective)
Field: Fieldname2 (field_fieldname2) (translated) (selective)
Content: Fieldname3 (field_fieldname3) (translated) (selective)
Comment #8
anouHello,
Thanks for the patch but it doen't apply any more (I think because of lines break that aren't in original module file).
I had to do do it "a la mano" but I still got the error (it's in french but the error is the same ;-) ):
Just for info, as you can read in the error, I'm using a taxonomy term for the select (so it needs a relation)....
Thanks for any help on this.
Comment #9
cmseasy CreditAttribution: cmseasy commentedI switched to Facet, following this workflow: http://beautiful7mind.wordpress.com/2013/03/10/step-by-step-how-to-imple...
Stil testing, but looks great: with facet you can create selective search (filtering) in an i18n environment. Maybe usefull for others.
Comment #10
Anonymous (not verified) CreditAttribution: Anonymous commented~
Comment #11
Anonymous (not verified) CreditAttribution: Anonymous commentedHi
i patched #4 manually both to alpha2 and to dev version. results:
they work fine with regard to translation, that is translations show up properly, but the filter itself doesn't work anymore, that is filtered content is not found. in other words: exactley the same result as described in #7
Every idea to solve this is much apreciated!"
Regards
sunbam
Comment #12
anouHello,
I didn't manage to resolve this issue but I found a way to get around it via a custom module and hook_form_alter(). You must use for example taxonomy term: term (selective) field for exposed filter and not the one with both "...(selective)(translated)". This way you get at least the options filtered by the view's results. Only not translated.
Then in your custom module:
This code is valid for terms translated via entity translation. You must use i18n_taxonomy_term_get_translation($term, $langcode) if you translate them via i18n and adapt the code.
Comment #13
skyredwangAs mentioned above, the patch made the translation work, but broke the filter
Comment #14
jannis CreditAttribution: jannis commentedThe patch supplied in #4 works to stop the error message.
However -- the exposed filter still shows the UNTRANSLATED option.
AND
the filter breaks and returns nothing when selected. The view must be reset.
This is frustrating! Everything else i18n seems to work great.
Does anyone have a hack / patch to make this work ? A workaround? A suggestion?
Comment #15
anou@jannis: have you tried the custom module like I propose in comment #12
Unfortunately I didn't find a way to solve the issue via a patch.
Comment #16
jannis CreditAttribution: jannis commentedHERE'S A SOLUTION I'VE FOUND THAT WORKS TO TRANSLATE SELECTIVE FILTERS:
Important to note: i'm not using (translated) filters from i18n_views to do this:
I've modified one file: views_hacks\views_filters_selective\views_handler_filter_selective.inc
If you want exposed selective filters that will automatically translate the exposed values - here is code that will support it. A few notes: i'm using entity translation to translate individual fields. I'm using 'title' to turn node titles in translatable fields.
Fields that are 'select boxes' show up easier, if you're using fields (like 'title' for example) to filter content, you're going to have to name the field in the code (in my example i'm using if ($this->table == 'field_data_field_title_field') to send the array of titles as options for the filter.
Anyways -- here is the ENTIRE views_handler_filter_selective.inc file (if a more experienced Drupaler can create a patch or clean up this code, that'd be great!):
<?php
class views_handler_filter_selective extends views_handler_filter_in_operator {
static $results;
function get_value_options() {
$this->value_options = array(0 => t('Actual values will be available at run-time'));
if (empty($this->view->selective_oids) && !empty($this->view->inited)) {
$handler = _views_filters_selective_get_handler($this->definition['proxy']);
$oids = $this->get_oids();
//grabs the oids from the filter -- then grabs the titles
$newoptions = array();
foreach($oids as $key => $value){
$currentnode = node_load($value);
$newoptions[$key] = $currentnode->title;
}
//if this table is a title (or other non-check-box-field), define it here. the else portion will translate the check-box-fields
if ($this->table == 'field_data_title_field'){$options = $newoptions;}
else{$options = empty($oids) ? array() : call_user_func($handler, $this, $oids);}
if (!empty($options)) {
// Encode the values to keep special chars.
$this->value_options = array_combine(array_map('urlencode', array_values($options)), array_values($options));
}
// Modify value_options to include title for term node reference fields.
if ($this->definition['proxy'] == 'views_handler_filter_term_node_tid') {
foreach ($this->value_options as $tid) {
$result = db_query('SELECT name FROM {taxonomy_term_data} WHERE tid = :tid', array(':tid' => $tid));
$title = $result->fetchField();
if (!empty($title)) {
$this->value_options[$tid] = $title;
}
}
}
// Remove empty values.
$this->value_options = array_diff_key($this->value_options , array("" => NULL));
// Translate list options
$field = field_info_field($this->definition['field_name']);
foreach($this->value_options as $key => $value){
$options = array();
//$translate = i18n_field_type_info($field['type'], 'translate_options');
if (($translate = i18n_field_type_info($field['type'], 'translate_options')) && !empty($this->value_options)){
$this->value_options[$key] = $translate($field)[$value];}
else{
} }
// Re-sort results based on title.
asort($this->value_options);
}
}
function stringid($keys) {
return 'views:' . implode(':', $keys);
}
function value_form(&$form, &$form_state) {
parent::value_form($form, $form_state);
// Avoid the 'illegal values' Form API error.
$form['value']['#validated'] = TRUE;
}
function query() {
// Decode the values to restore special chars.
$this->value = array_map('urldecode', $this->value);
parent::query();
}
function get_oids() {
$exposed_input = isset($this->view->exposed_input) ? $this->view->exposed_input : array();
$signature = md5(serialize(array(
'name' => $this->view->name,
'args' => $this->view->args,
'input' => $exposed_input,
)));
if (empty(self::$results[$signature])) {
// Clone the view and get all results.
$view_copy = views_get_view($this->view->name);
if (!$view_copy) return NULL;
$view_copy->selective_oids = TRUE;
$view_copy->set_exposed_input($exposed_input);
$view_copy->set_arguments($this->view->args);
$view_copy->set_items_per_page(0);
if (isset($_GET['items_per_page'])) {
$items_per_page = $_GET['items_per_page'];
unset($_GET['items_per_page']);
}
$view_copy->execute($this->view->current_display);
if (isset($items_per_page)) {
$_GET['items_per_page'] = $items_per_page;
}
$oids = array();
foreach ($view_copy->result as $row) {
$oids[] = $row->{$view_copy->base_field};
}
if (empty($this->view->base_field)) {
$this->view->base_field = $view_copy->base_field;
}
self::$results[$signature] = $oids;
$view_copy->destroy();
}
return self::$results[$signature];
}
}
Comment #17
ggeerolf CreditAttribution: ggeerolf commentedCreating an extra module as mentioned in #14 did the trick.
I just replaced
$translated_term[$tid] = isset($term->name_field['the_desired_language_code']) ? $term->name_field['the_desired_language_code'][0]['safe_value'] : $term->name_field['original_language_code'][0]['safe_value'];
by$translated_term[$tid] = i18n_string('taxonomy:term:' . $term->name . ':name', $term->name);
, where $term is my taxonomy-object.Comment #18
georgemastro CreditAttribution: georgemastro commentedThis is what actually worked for me.
Comment #19
infojunkieThis module has been deprecated in favour of https://drupal.org/project/views_selective_filters. Please test there and reopen if necessary.