This might apply to all relationship filters, but I've only tested it with taxonomy filters via a taxonomy field relationship.

Steps to reproduce:

  1. Create a new view
  2. Add a taxonomy term field as a relationship
  3. Add an exposed filter for the taxonomy term
  4. Create a page
  5. Create an attachment
  6. enable "Inherit exposed filters" setting in attachment and attach to page
  7. Load page view and filter by taxonomy term
  8. Attachment doesn't inherit taxonomy filters

I've attached a view that replicates this behavior (it uses the article content type and tags taxonomy).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

duellj’s picture

Title: Inherited exposed filters in attachments don't work with taxonomy relationship filters » Inherited exposed filters in attachments doesn't work with taxonomy term filter
FileSize
6.23 KB

Sorry, the relationship was a red herring. Just create a simple page and attachment with a taxonomy term ID filter, and the attachment won't inherit the filter. Attaching new test view with relationship removed.

duellj’s picture

Ok, so here's the problem as I can see it:

In views_handler_filter_term_node_tid::accept_exposed_input:

    // If it's optional and there's no value don't bother filtering.
    if ($this->options['expose']['optional'] && empty($this->validated_exposed_input)) {
      return FALSE;
    }

so the filter isn't computed unless $this->validated_exposed_input is set. In views_handler_filer_term_node_tid, validated_exposed_input is only set in exposed_validate:

        $this->validated_exposed_input = (array) $form_state['values'][$identifier];

validated_exposed_input is run only in views_exposed_form_validate for the main page view's exposed form, so it's never run for the attachment.

duellj’s picture

Status: Active » Needs review
FileSize
1.37 KB

Since the filters are being validated already, could the just the raw input be used for attachment views that inherit exposed input? There might be something I'm missing, but the attached patch let's attached taxonomy filters inherit the values correctly.

merlinofchaos’s picture

Assigned: Unassigned » dawehner

I don't sufficiently understand D7 taxonomy to be able to review this.

merlinofchaos’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Status: Needs review » Patch (to be ported)

Ok, I think I get this now. Committed with a slight change (isset changed to !empty) and not getting rid of the blank line. Needs to be ported to D6.

dawehner’s picture

Status: Patch (to be ported) » Fixed

And commited.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

pinkonomy’s picture

I have the same problem,should I apply the patch from #3 on the Views module?I am using views 7.x-3.3 .Thanks

seattlehimay’s picture

Version: 6.x-3.x-dev » 7.x-3.3
Assigned: dawehner » Unassigned
Status: Closed (fixed) » Active

Like #8, I have this problem still.

Filters are not inherited at all (neither text, nor pulldown taxonomy) in my attachment. I am using postgres, if it matters.

Not sure how I can provide useful information for you.

Hanpersand’s picture

Subscribe. This is happening to me in 7.x-3.5.

Hanpersand’s picture

Version: 7.x-3.3 » 7.x-3.5
nikonvulcano’s picture

This is happening to me in 7.x-3.5 whit Taxonomy term filter but ONLY with AUTOCOMPLETE active, while with DROPDOWN MENU it's OK !!

webdrips’s picture

I have the same problem with autocomplete enabled. There's a somewhat similar bug for taxonomies marked for localization using autocomplete. I wonder if the issue could be related?

I can try to find it and post it if it will be helpful.

FrancescoQ’s picture

I don't know if it was the same problem, but i fought with exposed filters and attachments today... i discovered that "inherit filters" means "inherit filter values"... so you have to configure the filter section in the same way on the attachment and its main view. In this way worked for me.

redsky’s picture

Version: 7.x-3.5 » 7.x-3.10
Issue summary: View changes

I thought I'd provide an update since it's been a while.

I'm using views-7.x-3.10 and have this same problem today. I have a page view with an exposed filter criteria. One of those criteria is a taxonomy term. I have an attachment which inherits the filter criteria. When it is setup as autocomplete the attachment displays no results when it is a dropdown it works. It's a large list and an autocomplete would be more appropriate for this use case.

andrew.eatherington@gmail.com’s picture

It looks like #14 FrancescoQ is correct putting the exact same exposed filter on the attachment seems to inherit the values

karan.gshar’s picture

Found the solution:
There are two issues that occur with using autocomplete:

1)If you debug your query in hook_views_query_alter, on initial page load you will find that under 'where' an empty string is being passed to your taxonomy term filter and since filter looks for a tid and an empty string is no 'tid', hence attachment shows up but with no results.

2) If you put a value in your taxonomy term expose filter, then unlike dropdown it takes string as value to check against where clause instead of tid, so you have to convert it into tid.

Here's the example code:

/*
 * Implements hook_views_pre_render().
 */

function hook_views_query_alter(&$view, &$query) {
  if ($view->name == 'your_view_name') {
    if ($view->current_display == 'attachment_1') {
      // To debug do dpm($query);
      foreach ($query->where[1]['conditions'] as $key => $cond)
      {
        if($cond['field'] == 'your_taxonomy_term_filter_field') {

          //Scenario 1: On intial page load when you get empty string, just unset the condition
          if ($query->where[1]['conditions'][$key]['value'] == '') {
            unset($query->where[1]['conditions'][$key]);
          }

          //Scenario 2: When you input a value in your taxonomy term expose filter
          else {
            //Convert string into required tid and save it again
            $term_data = current(taxonomy_get_term_by_name($query->where[1]['conditions'][$key]['value']));
            $query->where[1]['conditions'][$key]['value'] = $term_data->tid;
          }
        }
      }
    }

  }
}
rosemaryreilman’s picture

I'm also having a similar issue with views version: 7.x-3.17
I thought it was tied to the main view having ajax enabled. I'm trying hook_views_query_alter and while that works when you load the page it does not work on ajax submission.

I'm using taxonomy filter, search terms and date fields.