1

This does not work anymore - seems to relate to Views 2.18 last update. I tried to roll Views back to 2.16, but this is impossible, so I cannot confirm.

1) I have an autocomplete filter for terms of a vocabulary beside one other autocomplete filter for node title

2) I set a field "All terms" for that vocabulary. the id for this field is "tid"

3) I set an exposed filter "Taxonomy term name" with "content" as operator, "tid" as filter identifier

The views_autocomplete_filter.inc code is the following - some tweaks prefixed "JV" included and a dpm call for debug purpose (a single row of the views result for suggestions):

<?php
// $Id: views_autocomplete_filters.module,v 1 vasike Exp $

/**
 * @file
 * Common functions for Autocomplete Filters module.
 */
/**
 * Menu callback; Retrieve a pipe delimited string of autocomplete suggestions.
 */
// JV www.drupal.org/node/1303362
//function views_autocomplete_filter($field_name = NULL, $view_name, $view_display, $string = '') {
function views_autocomplete_filter($field_name = NULL, $view_name, $view_display, $arguments, $string = '') {
// 
 static $autocomplete_filter_results;
 $results_id = $field_name.'_'.$view_name.'_'.$view_display.'_'.$string;
 if (isset($autocomplete_filter_results[$results_id])) {
      drupal_json($autocomplete_filter_results[$results_id]);
        return;
 }
 $matches = array();
 //$view_args = array();
 $view = views_get_view($view_name);
 $view->set_display($view_display);
 // JV https://www.drupal.org/node/1303362
 /* 
  * If there are no arguments present then the query string will change from
  * /field_name/view_name/view_display/arguments/string
  * to
  * /field_name/view_name/view_display/string
  * and therefore the 'argument' parameter will actually be the string we are 
  * looking for. 
  */
  $args = array();
  if ($string == ''){
    $string = $arguments;
  }
  // If there are (comma-separated)arguments, put them back in an 
  // array and set the view arguments
  else{
    $args = explode(',', $arguments);
    $view->set_arguments($args);
  }

// end JV
 // force to have no limit for results
 $view->display_handler->set_option('items_per_page', 0);
 $view->handler->items_per_page = $view->pager['items_per_page'] = 0;
 $currentview = $view->display[$view_display];
 // exposed form field name
 if ($currentview->handler->options['defaults']['filters']) {
     $currentview = $view->display['default'];
 } else {
     $currentview = $view->display[$view_display];
 }
 $field_filter = $currentview->handler->options['filters'][$field_name];
 // assign string value to the exposed text filter
 $view->exposed_input[$field_filter['expose']['identifier']] = $string;

 $item = $view->get_item($view_display, 'filter', $field_name);
 // overwrite the fields for the view
 $view->display[$view_display]->handler->options['fields'] = array($field_name => $item);
 $view->display[$view_display]->display_options['fields'] = array($field_name => $item);
 $view->execute($view->current_display);

 $currentview = $view->display[$view_display];
 // views field handler data
 $field = $currentview->handler->handlers['field'][$field_name];
 $field_alias = $field->field_alias;

 dpm ($view->result[1]);

 foreach ($view->result as $id => $row) {
   // Add a class wrapper for a few required CSS overrides.
     if (!empty($row->$field_alias)) {
        $matches[$row->$field_alias] = '<div class="reference-autocomplete">'. $row->$field_alias .'</div>';
     }
 }
 if (!empty($matches)) {
     $autocomplete_filter_results[$results_id] = $matches;
 } elseif (!empty($view->result)) {
     $matches[''] = '<div class="reference-autocomplete">'. t('The %field field of this filter should be present also in the result (could be excluded from display).', array('%field' => $field_filter['expose']['label'])) . '</div>';
 } else {
// JV https://www.drupal.org/node/1303362
//   $matches[''] = '<div class="reference-autocomplete">'. t('The %string return no results. Please try something else.', array('%string' => $string)) . '</div>';
     $matches[''] = '<div class="reference-autocomplete">'. t('\'%string\' returned no results. Please try something else.', array('%string' => $string)) . '</div>';
// end JV
 }
 drupal_json($matches);
}

This what I get in dpm

(Object) stdClass
nid (String, 5 characters ) 14287
og_access_post_og_public (String, 1 characters ) 1
node_language (String, 0 characters )
node_title (String, 134 characters ) Characterization and Estimation of the Variatio...
node_data_field_complement_titre_field_complement_titre_value (NULL)
node_type (String, 4 characters ) file | (Callback) file();
node_vid (String, 5 characters ) 24675
node_node_data_field_manifestation_title (String, 7 characters ) GSI2015
node_node_data_field_manifestation_nid (String, 5 characters ) 11781
node_node_data_field_manifestation_language (String, 0 characters )
node_data_field_edition_revue_field_edition_revue_nid (NULL)
node_data_field_ismemberof_field_ismemberof_nid (NULL)
og_ancestry_nid (String, 5 characters ) 14287
node_created (String, 10 characters ) 1446972480
node_node_data_field_manifestation_node_data_field_date_field_date_value (String, 19 characters ) 2015-10-28T00:00:00
node_node_data_field_manifestation_node_data_field_date_field_date_value2 (String, 19 characters ) 2015-10-30T00:00:00
node_node_data_field_manifestation_type (String, 5 characters ) event
node_node_data_field_manifestation_vid (String, 5 characters ) 24998
node_node_data_field_manifestation_created (String, 10 characters ) 1415634960
  • There is no trace of taxonomy information in vews result, the autocomplete will never get filled.
  • the effect of ticking the box "Use Autocomplete" is nil: autocomplete is always active as soon as the operator is set to "contains".

By the way, taxonomy autocomplete filter in views should be a very basic requirement. If there is no way to fix this, is there any other solution beside Views hacks' autocomplete filter sub-module?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.