The module doesn't work well with the grouped filters.

Created on 11 August 2023, over 1 year ago
Updated 5 September 2024, 4 months ago

Problem/Motivation

When using the grouped filters and selecting multiple values, only the last one is displayed and it has wrong value for thedata-remove-selector attribute. The attribute contains string with label value e.g. 'A', but the argument in the URL for the filter contains key value from the group items e.g. '1'.

Steps to reproduce

Add filter for example for the title of the entity. Use settings similar to the attached screenshots.

Proposed resolution

We should get values from the exposed input when the filter is grouped, because $filter->value returns only one value (looks like the last selected one).
I've used such code in custom module to fix it:

/**
 * Implements hook_batch_views_filters_summary_info_alter().
 */
function mymodule_views_filters_summary_info_alter(array &$info, FilterPluginBase $filter) {
// Fix grouped filter like 'Starting with'.
  if ($filter->getPluginId() === 'string' &&
    $filter->isAGroup() &&
    !empty($filter->options['group_info']['group_items']) &&
    is_array($filter->options['group_info']['group_items'])
  ) {
    $exposed_input = $filter->view->getExposedInput();
    $exposed_values = $exposed_input[$info['id']] ?? [];
    $info['value'] = is_array($exposed_values) ? $exposed_values : [$filter->value];
    $group_items = $filter->options['group_info']['group_items'];
    $values = [];
    foreach ($info['value'] as $index => $index_value) {
      $values[] = [
        'id' => $index,
        'raw' => $index_value,
        'value' => $group_items[$index]['value'],
      ];
    }
    $info['value'] = $values;
  }
}

Maybe body of the function can be added to the ViewsFiltersSummary::buildFilterDefinition() method to fix such cases by default?

πŸ› Bug report
Status

Postponed: needs info

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine khiminrm

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024