Problem/Motivation

When adding an exposed and grouped user_name filter, the value doesn't validate correctly. It issue stems from the entity reference autocomplete field handling values using the target_id key, and loaded entities.

This is exactly the same issue as reported in #2576927: Grouped exposed taxonomy filter fails validation for autocomplete widget. Please check it out for more details.

Other changes applied in the merge request are just allowed new tests to pass. There were 2 issues:
1) Default value of the filter was trying to be processed twice but failed with the exception. More information is in duplicated issue: #3250352: Username views filter should not process default value twice . Fixed in this commit: https://git.drupalcode.org/project/drupal/-/merge_requests/1445/diffs?co...
2) There was a PHP notice in \Drupal\user\Plugin\views\filter\Name::validateExposed method, that was fixed in this commit: https://git.drupalcode.org/project/drupal/-/merge_requests/1445/diffs?co...

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). Make sure the group item is using autocomplete widget
  4. Add at least one item to the group configuration (e.g. "admin")
  5. Submit

Proposed resolution

Apply the same fix and test coverage as in #2576927: Grouped exposed taxonomy filter fails validation for autocomplete widget. Also, make additional fixes to let tests pass.

Remaining tasks

Review, commit.

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

Issue fork drupal-2920039

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

grathbone created an issue. See original summary.

grathbone’s picture

grathbone’s picture

Status: Active » Needs review
grathbone’s picture

Status: Needs review » Needs work

Running into weird issues. Checking into it.

dagmar’s picture

Issue tags: -views, -user

Can you specify how to replicate this in the issue summary?

grathbone’s picture

grathbone’s picture

Issue summary: View changes
grathbone’s picture

@dagmar updated and included a reference to a similar issue.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Matroskeen’s picture

Component: user.module » views.module
Assigned: grathbone » Unassigned
Issue tags: +Bug Smash Initiative

Looking at the issue description and the published patch, I can confirm that this issue is a duplicate of this one: #2576927: Grouped exposed taxonomy filter fails validation for autocomplete widget. Let's continue there. I'll ask someone to make sure we transfer issue credits.

Thanks for your contributions!

Matroskeen’s picture

Version: 8.9.x-dev » 9.4.x-dev
Issue summary: View changes
Status: Needs work » Needs review

After giving it a second thought and discussing it with @lendude in Slack, it was decided to keep those issues separate.

I'm updating the issue summary and moving to NR for an open merge request. Hopefully, tests will pass.

Matroskeen’s picture

Hiding initial patch because we're using a merge request flow.

Matroskeen’s picture

I realized that target branch was 8.9.x, and my rebase/merge attempts failed... That's why there is a new merge request against 9.4.x, where I tried to address @lendude's feedback that was added in https://git.drupalcode.org/project/drupal/-/merge_requests/1445

I also added a helper method and changed the way the view results are verified in the test. I think that current approach is not reliable. It's looking for user ID in the whole page markup. If the user id (e.g. 2) is available somewhere else, then test is not quite correct.

The method is almost identical as in #3251394: Introduce ViewTestBase::assertIds to simplify view results testing, so maybe it's worth pushing the issue with the helper method first.

Lendude’s picture

Status: Needs review » Reviewed & tested by the community

Yeh the refactoring of the test makes sense to me, let's keep that.

Went through this again and this look good.

quietone’s picture

Status: Reviewed & tested by the community » Needs work

Sorry, This will need to be on 10.0.x I edited the MR to be on 10.0.x but was informed it needed a rebase. It will still need an MR for 9.5.x

Matroskeen’s picture

Version: 9.4.x-dev » 10.0.x-dev
Status: Needs work » Needs review
FileSize
8.85 KB

Uploading a patch to be able to run tests for all active branches.

Matroskeen’s picture

Uploading a patch with a small difference in buildExposedFiltersGroupForm() method.

I was just thinking that changing values in the plugin object might be not a good idea because it transforms the list of IDs to a single string.
Instead, we should format the string only for the form element. It was initially changed in #2576927: Grouped exposed taxonomy filter fails validation for autocomplete widget, so I'm just trying to keep the consistency.

I'm leaving it as NR because of these changes. The interdiff is the last commit in the merge request.

Status: Needs review » Needs work

The last submitted patch, 23: 2920039-23.patch, failed testing. View results

Matroskeen’s picture

I just discovered something else, which is described in another issue: #3280477: Name and TaxonomyIndexTid filter plugins have incorrect default values in grouped filters.

The tests were failing because the form element already had a default value from the previously configured "Value", when the filter type was "single". It's a pretty edge case because you'd need to create a single exposed filter first, add some values, and then switch to grouped filter.

To move forward, I just added an extra condition to avoid type errors and suggest fixing this in a follow-up that I created.

Matroskeen’s picture

Status: Needs work » Needs review
FileSize
8.93 KB
Lendude’s picture

Status: Needs review » Needs work

Looks really good, just some nitpicks really.

  1. +++ b/core/modules/user/src/Plugin/views/filter/Name.php
    @@ -39,14 +44,31 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
    +    // Autocomplete puts the values in target_id. Move the values to the
    +    // expected depth.
    

    Might be good to specify what is 'expecting' this?

  2. +++ b/core/modules/user/src/Plugin/views/filter/Name.php
    @@ -124,4 +146,19 @@ public function adminSummary() {
    +        $users = User::loadMultiple($item['value']['#default_value']);
    

    Static :(

  3. +++ b/core/modules/user/tests/src/Functional/Views/HandlerFilterUserNameTest.php
    @@ -127,6 +127,38 @@ public function testAdminUserInterface() {
    @@ -137,6 +169,10 @@ public function testExposedFilter() {
    

    The changes in this test method are unrelated right? If so, lets not do that here, it makes it more difficult to review

Matroskeen’s picture

Status: Needs work » Needs review

@lendude thanks for the review!

The first 2 items were addressed. The 3rd one is not done yet, because I think they should remain.
In this test we introduced a new helper method - HandlerFilterUserNameTest::assertIds(). Therefore, we use a new method for other assertions to make it more bullet-proof. For example, the previous assertion is:
$this->assertSession()->pageTextContains($account->id());
If there is a text on the page that matches user ID, it'll be a false positive. With a new approach, we're looking only into view results.

A similar change was done in the last commit. After injecting the entity type manager, I changed this line, although it is out of scope: https://git.drupalcode.org/project/drupal/-/merge_requests/1473/diffs#62...

P.S. I encourage you to use MR to add comments. The patch is just a copy, that allows me to run tests against multiple Drupal versions.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
FileSize
150 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 10.0.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.