Create a view and configure a filter with the following options set

  • Expose this filter to visitors, to allow them to change it
  • Grouped filters
  • Allow multiple selections
  • Widget type = Select
  • Tick at least one box in the default column.

Works so far: when viewing the view, the items that were set as default are checked by default.

Now add a second exposed filter. Don't think the settings matter too much so long as it is exposed. Still works, see screenshot Right.png.

Now change the order of these two filters and the bug occurs: when viewing the view, no items are checked by default. See screenshot Wrong.png.

Export of the view in this final not-working state:

$view = new view();
$view->name = 'test';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Test';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Test';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'table';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Filter criterion: Content: Author uid */
$handler->display->display_options['filters']['uid']['id'] = 'uid';
$handler->display->display_options['filters']['uid']['table'] = 'node';
$handler->display->display_options['filters']['uid']['field'] = 'uid';
$handler->display->display_options['filters']['uid']['value'] = array(
  0 => '1',
);
$handler->display->display_options['filters']['uid']['group'] = 1;
$handler->display->display_options['filters']['uid']['exposed'] = TRUE;
$handler->display->display_options['filters']['uid']['expose']['operator_id'] = 'uid_op';
$handler->display->display_options['filters']['uid']['expose']['label'] = 'Author uid';
$handler->display->display_options['filters']['uid']['expose']['operator'] = 'uid_op';
$handler->display->display_options['filters']['uid']['expose']['identifier'] = 'uid';
$handler->display->display_options['filters']['uid']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
);
/* Filter criterion: Content: Body (body) */
$handler->display->display_options['filters']['body_value']['id'] = 'body_value';
$handler->display->display_options['filters']['body_value']['table'] = 'field_data_body';
$handler->display->display_options['filters']['body_value']['field'] = 'body_value';
$handler->display->display_options['filters']['body_value']['group'] = 1;
$handler->display->display_options['filters']['body_value']['exposed'] = TRUE;
$handler->display->display_options['filters']['body_value']['expose']['operator_id'] = 'body_value_op';
$handler->display->display_options['filters']['body_value']['expose']['label'] = 'Body (body)';
$handler->display->display_options['filters']['body_value']['expose']['operator'] = 'body_value_op';
$handler->display->display_options['filters']['body_value']['expose']['identifier'] = 'body_value';
$handler->display->display_options['filters']['body_value']['expose']['multiple'] = TRUE;
$handler->display->display_options['filters']['body_value']['is_grouped'] = TRUE;
$handler->display->display_options['filters']['body_value']['group_info']['label'] = 'Body (body)';
$handler->display->display_options['filters']['body_value']['group_info']['identifier'] = 'body_value';
$handler->display->display_options['filters']['body_value']['group_info']['multiple'] = TRUE;
$handler->display->display_options['filters']['body_value']['group_info']['default_group_multiple'] = array(
  1 => '1',
);
$handler->display->display_options['filters']['body_value']['group_info']['group_items'] = array(
  1 => array(
    'title' => 'Green',
    'operator' => 'contains',
    'value' => 'Green',
  ),
  2 => array(
    'title' => 'Red',
    'operator' => 'contains',
    'value' => 'Red',
  ),
);

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'test';
$handler->display->display_options['menu']['type'] = 'normal';
$handler->display->display_options['menu']['title'] = 'Test view';
$handler->display->display_options['menu']['weight'] = '0';
$handler->display->display_options['menu']['name'] = 'main-menu';
$handler->display->display_options['menu']['context'] = 0;
$handler->display->display_options['menu']['context_only_inline'] = 0;

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MrHaroldA’s picture

Confirmed!

And I even discovered another issue with the grouped items -vs- default values: the pager sets unset filters.

I have a view that groups 2 roles in 2 select boxes:
[ ] Role 1 and 2
[ ] Role 3 and 4

The defaults aren't set, but more unfortunate is that when you navigate to the second page, this is added to the url: ?role[1]=0&role[2]=0

Which results in this select list:
[X] Role 1 and 2
[X] Role 3 and 4

So I guess there's something wrong with the filter input handling ...

MrHaroldA’s picture

Version: 7.x-3.10 » 7.x-3.x-dev
Priority: Normal » Major
Status: Active » Needs review
FileSize
547 bytes

I found one bug in the grouped filter handler; I'm looking into the bug with the pager, or the parsing of the input from the pager ...

Bumping as 'major' because this is quite a bug in the standard views filter handler.

Next up is the pager; and later on I'll check the Drupal 8 port.

AdamPS’s picture

Status: Needs review » Reviewed & tested by the community

@MrHaroldA Thanks for the patch - works for me.

MrHaroldA’s picture

Cool!

Can you confirm my issues with the pager? It's setting all options here instead of using the user's selection.

AdamPS’s picture

For the pager problem, I think you should raise a new issue, else it gets hard for other people to understand. Ideally you would describe the exact scenario and export as simple a view as possible that exhibits the bug.

I have raised 2 other issues with multiple-selection exposed filters (#2452729: Cannot clear default for exposed multi-valued taxonomy/select list/entityref filter, #2452661: Exposed filter with multiple selections of taxonomy "is none of" doesn't work), so I guess it's a buggy area. Possibly it would help to start a meta-issue to group them.

(But yes I think I see the same with the pager - I will add a comment to say so to your new issue.)

MrHaroldA’s picture

Thanks for confirming! I was going to open (and reference) a new issue for it. I've been looking at some strange code today; cannot grasp entirely how this is supposed to work, if it did work at any point.

fonant’s picture

Confirming that patch #2 fixes the problem of grouped filter defaults not working.

colan’s picture

We've recently switched our testing from the old qa.drupal.org to DrupalCI. Because of a bug in the new system, #2623840: Views (D7) patches not being tested, older patches must be re-uploaded. On re-uploading the patch, please set the status to "Needs Review" so that the test bot will add it to its queue.

If all tests pass, change the Status back to "Reviewed & tested by the community". We'll most likely commit the patch immediately without having to go through another round of peer review.

We apologize for the trouble, and appreciate your patience.

MrHaroldA’s picture

As requested in #8 ...

AdamPS’s picture

Status: Needs review » Reviewed & tested by the community

As requested in #8 ...

zmove’s picture

Confirm that the patch work, would be great to see it commited to resolve that old issue.

DamienMcKenna’s picture

Status: Reviewed & tested by the community » Fixed
Parent issue: » #2903944: Plan for Views 7.x-3.19 release

Committed, thanks.

Status: Fixed » Closed (fixed)

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