Hello,
We're using a module called combined_termref to allow multiple vocabularies on a Term Reference
field.
When trying to add an exposed filter in a view based on that Term Reference field, only the first vocabulary is handled, the other ones are simply ignored (both in the admin UI and on the view page).
Problem/Motivation
Views cannot handle Term Reference fields that are configured to use multiple vocabularies.
How to reproduce:
- Enable Combined Termref module
- Create a term reference field and set multiple vocabularies that will supply options
- Add an exposed filter on that term reference field
- -> Only the first vocabulary is taken into account
Proposed resolution
Patch Views module.
Following function in /modules/taxonomy.views.inc is an example of code that is handling one single vocabualry only (I guess there may be other places where this happens):
/**
* Implements hook_field_views_data().
*
* Views integration for taxonomy_term_reference fields. Adds a term relationship to the default
* field data.
*
* @see field_views_field_default_views_data()
*/
function taxonomy_field_views_data($field) {
$data = field_views_field_default_views_data($field);
foreach ($data as $table_name => $table_data) {
foreach ($table_data as $field_name => $field_data) {
if (isset($field_data['filter']) && $field_name != 'delta') {
$data[$table_name][$field_name]['filter']['handler'] = 'views_handler_filter_term_node_tid';
$data[$table_name][$field_name]['filter']['vocabulary'] = $field['settings']['allowed_values'][0]['vocabulary']; // This instruction only takes the first element (vocabulary) of the array.
}
}
// Add the relationship only on the tid field.
$data[$table_name][$field['field_name'] . '_tid']['relationship'] = array(
'handler' => 'views_handler_relationship',
'base' => 'taxonomy_term_data',
'base field' => 'tid',
'label' => t('term from !field_name', array('!field_name' => $field['field_name'])),
);
}
return $data;
}
User interface changes
The views admin UI should allow the display of multiple vocabs when setting up a filter on concerned fields.
Related issues
- Drupal Core: #1623054: Allow multiple vocabularies in term reference fields
- Combined Termref: #2104311: Make Views exposed filter accept multiple vocabularies
Remaining tasks
- Write a patch
- Review
- Tests?
- Documentation?
Comments
Comment #2
Ludo.RThis patch could probably serve as a base to patch Views module: https://www.drupal.org/node/2104311#comment-10365541
I leave to Views maintainers to decide what is the best approach.
Comment #3
kopeboy CreditAttribution: kopeboy commentedYes please!!