Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
For example, using two exposed Taxonomy filters for two different vocabularies. Settings the first filter to "" and the second to a specific value results in the this query without Filter Pack enabled:
SELECT ....
WHERE (node.status <> 0) AND (node.type in ('directory')) AND (term_node.tid = 23)
With Filter Pack enabled, the following SQL is generated:
SELECT ....
WHERE (node.status <> 0) AND (node.type in ('directory')) AND (term_node.tid = 0)
Below is an export of the view in question, if that helps. Note that it relies on a node type of "directory" and a few Taxonomy vocabularies. But it should give you a basic idea of what I was doing if my explanation above was lacking.
$view = new view;
$view->name = 'tester';
$view->description = 'test';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'field_dir_firstname_value' => array(
'label' => 'First name',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'link_to_node' => 0,
'label_type' => 'widget',
'format' => 'default',
'multiple' => array(
'group' => TRUE,
'multiple_number' => '',
'multiple_from' => '',
'multiple_reversed' => FALSE,
),
'exclude' => 0,
'id' => 'field_dir_firstname_value',
'table' => 'node_data_field_dir_firstname',
'field' => 'field_dir_firstname_value',
'relationship' => 'none',
),
'field_dir_lastname_value' => array(
'label' => 'Last name',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'link_to_node' => 0,
'label_type' => 'widget',
'format' => 'default',
'multiple' => array(
'group' => TRUE,
'multiple_number' => '',
'multiple_from' => '',
'multiple_reversed' => FALSE,
),
'exclude' => 0,
'id' => 'field_dir_lastname_value',
'table' => 'node_data_field_dir_lastname',
'field' => 'field_dir_lastname_value',
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'status' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'node',
'field' => 'status',
'relationship' => 'none',
),
'type' => array(
'operator' => 'in',
'value' => array(
'directory' => 'directory',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
'tid' => array(
'operator' => 'or',
'value' => array(),
'group' => '0',
'exposed' => TRUE,
'expose' => array(
'use_operator' => 0,
'operator' => 'tid_op',
'identifier' => 'tid',
'label' => 'Research Group',
'optional' => 1,
'single' => 1,
'remember' => 0,
'reduce' => 0,
),
'type' => 'select',
'limit' => TRUE,
'vid' => '1',
'id' => 'tid',
'table' => 'term_node',
'field' => 'tid',
'hierarchy' => 0,
'relationship' => 'none',
'reduce_duplicates' => 0,
'views_filter_pack_element_type' => '',
),
'tid_1' => array(
'operator' => 'or',
'value' => array(),
'group' => '0',
'exposed' => TRUE,
'expose' => array(
'use_operator' => 0,
'operator' => 'tid_1_op',
'identifier' => 'tid_1',
'label' => 'Employment Type',
'optional' => 1,
'single' => 1,
'remember' => 0,
'reduce' => 0,
),
'type' => 'select',
'limit' => TRUE,
'vid' => '5',
'id' => 'tid_1',
'table' => 'term_node',
'field' => 'tid',
'hierarchy' => 0,
'relationship' => 'none',
'reduce_duplicates' => 0,
'views_filter_pack_element_type' => NULL,
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('style_plugin', 'list');
$handler->override_option('style_options', array(
'grouping' => '',
'type' => 'ul',
));
$handler->override_option('row_options', array(
'inline' => array(
'field_dir_firstname_value' => 'field_dir_firstname_value',
'field_dir_lastname_value' => 'field_dir_lastname_value',
),
'separator' => ' - ',
));
Comments
Comment #1
peter-boeren CreditAttribution: peter-boeren commentedThanks Mikeker for your feedback.
I noticed that if there a two of more exposed filters of the same type such as vocabularies than my script doesn't kick in. In your example the first vocabulary will be joined as term_node and the second as term_node2
SELECT node.nid AS nid, node.language AS node_language, node.title AS node_title, term_data.name AS term_data_name, term_data.vid AS term_data_vid, term_data.tid AS term_data_tid FROM node node INNER JOIN term_node term_node ON node.vid = term_node.vid LEFT JOIN term_node term_node2 ON node.vid = term_node2.vid AND term_node2.tid != 0 LEFT JOIN term_data term_data ON term_node.tid = term_data.tid WHERE (node.status <> 0) AND (node.type in ('page')) AND (term_node2.tid = 4) LIMIT 0, 10
example of a function that uses 'table' and 'field' combination:
My script replaces parts of the query in hook_views_query alter by searching for the name of the table and the view. So I was able to reproduce the bug. The next step will be to solve it.
Comment #2
peter-boeren CreditAttribution: peter-boeren commented