Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293660

Name and TaxonomyIndexTid filter plugins have incorrect default values in grouped filters

$
0
0

Problem/Motivation

When switching an exposed filter type from " Single filter" to "Grouped filters", you might end up in a situation when default filter values are not correctly set in the form. It happens when you already had some value in "Value" field (when filter type was single), and then you switched to "Grouped" type. I'll share exact steps to reproduce to make it more clear.

Steps to reproduce

  1. Install Drupal with "Standard" profile
  2. Open content view (/admin/structure/views/view/content)
  3. Add an exposed grouped filter by "Authored by" (User).
  4. Keep it single and add some user in "Value" field, click "Apply"
  5. Open filter settings again and change filter type to "Grouped"
  6. You'll see that each group has default value, which is the value you selected in step #4
  7. If you set some values into your groups, and then reload the form again, you'll see different values, but they won't be formatted properly without #2920039: Views' User Name exposed group filter validation

After initial investigation, it was noticed that default value is being applied in these lines:

protected function valueForm(&$form, FormStateInterface $form_state) {
    $users = $this->value ? User::loadMultiple($this->value) : [];
    $default_value = EntityAutocomplete::getEntityLabels($users);
    $form['value'] = [
      '#type' => 'entity_autocomplete',
      '#title' => $this->t('Usernames'),
      '#description' => $this->t('Enter a comma separated list of user names.'),
      '#target_type' => 'user',
      '#tags' => TRUE,
      '#default_value' => $default_value,
      '#process_default_value' => FALSE,
    ];
}

Drupal\user\Plugin\views\filter\Name::valueForm method is called for each group and uses the same value. Later on, the value is being replaced by group value in Drupal\views\Plugin\views\filter\FilterPluginBase:

if (isset($this->options['group_info']['group_items'][$item_id]['value']) && $this->options['group_info']['group_items'][$item_id]['value'] != '') {
  $row['value']['#default_value'] = $this->options['group_info']['group_items'][$item_id]['value'];
}

It sets into #default_value a list of user IDs, but this is happening after ::valueForm is called and #default_value is properly formatted.

Proposed resolution

It needs more investigation.

Remaining tasks

Think about it.

There are no User interface, API or Data model changes.


Viewing all articles
Browse latest Browse all 293660

Trending Articles