A simple scenario. Content Type "Topic" has a text field "Category" which is a simple multi-select field that can have unlimited values (more than 1). So a topic can have 2 or more categories.

Then in my view I display all "topic" nodes. I want an exposed filter to let me filter by category, but be limited by the result set. No matter which direction I take, I cannot accomplish this.

It seems that the filter cannot pull any values out of a grouped limiting field, and this is the root of the problem.

Option #1: This is the one that should work.
Distinct: No
Field: Category: Group Multiple Values: Yes
Filter: Use field_category as limiter
Result: View rows display as expected, filter only contains . Fail

Option #2:
Distinct: No
Field: Category: Group Multiple Values: No
Filter: Use field_category as limiter
Result: View rows are duplicated for each category. Filter displays properly. Fail

Option #3:
Distinct: No
Field: Category: Group Multiple Values: Yes
Filter: Use default as limiter
Result: View rows display as expected. Filter contains values that exist in previous versions of node. Fail

Option #4:
Distinct: Yes
Field: Category: Group Multiple Values: No
Filter: Use default as limiter
Result: View rows display as expected. Filter contains values that exist in previous versions of node. Fail

Option #5:
Distinct: Yes
Field: Category: Group Multiple Values: No
Filter: Use field_category as limiter
Result: View rows display as expected. Filter only contains first value for category. Fail

Comments

aiquandol’s picture

Version:6.x-1.0-beta1» 6.x-1.x-dev

My bad, I'm actually using the dev version

aiquandol’s picture

I feel a solution coming on ;)

xl_cheese’s picture

You're not alone. I have the exact same behavior. I'm pretty sure the developer is working on making the limiting work with distinct set to yes.

Steven Monetti’s picture

After hours of work with Brent Hartmann we got the solution:

<?php
       
//Get all fields and remove the grouping if exists
       
$items = $view->get_items('field', $filter->view->current_display);
        foreach(
$items as $item) {
            if(
$item['multiple']['group'] == 1) {
               
$item['multiple'] = array(
                   
'group' => 0,
                   
'multiple_number' => '',
                   
'multiple_from' => '',
                   
'multiple_reversed' => FALSE,
                );
               
$view->set_item($filter->view->current_display, 'field', $item['field'], $item);
            }
        }
       
       
//Set distinct to false
       
$view->display_handler->set_option('distinct', 0);
?>

right before (around line 70)

<?php
$view
->set_display($filter->view->current_display);
?>
aiquandol’s picture

Here's a rundown of the above solution . . .

The default behavior of the module is to determine the result set via cloning the view and going through each row to see the value of the fields.

When fields are grouped, 1. they don't create a new row, and 2. they don't even show up in the view object.

So the way this solution works is by removing grouping and distinct from the clone, letting each field produce a new row, thereby allowing the rest of the program to run normally, parsing out the values.

xl_cheese’s picture

That was quick!

Can you explain the proper configuration to make this work? Is it one of the options that the OP laid out above?

aiquandol’s picture

It should satisfy a few of them actually

With this patch you should be able to use distinct -and- grouping while maintaining accurate limiting. It's only been tested when an actual limiting field has been selected for the filter options (not using default).

infojunkie’s picture

Status:Active» Fixed

Thanks for the in-depth analysis and the code fix!

I committed this fix, along with another to solve the default handling that incorrectly grabbed values from earlier revisions.

I'd be grateful if the 5 options in the OP could be tested against the latest dev release (12 hours from now or from CVS).

xl_cheese’s picture

Status:Fixed» Needs work
xl_cheese’s picture

Status:Needs work» Fixed

please disregard my note. I accidentally used the wrong module I had leftover on my computer. :P

Status:Fixed» Closed (fixed)

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