I find a bug while working on the Drupal 8.7.10 version and reproduces the same bug in version 8.8.5.
Steps to reproduce the bug:
1. Install fresh Drupal 8.8.5.
2. Create 2 roles, for example 'student' and 'teacher'.
3. Create users, which will have one of new created roles.
4. Create view to show users.
5. Add new view display: Entity Reference.
6. Select 'User: Name' as Search fields in Format -> Format -> Settings.
7. Add Role contextual filter and check "Allow multiple values" checkbox.
I expected to see the list of users who have one of the given roles.
But it show following sql query:
instead of given role id's, I saw '0' in the query.
Comments
Comment #2
mashot7Comment #3
le72I confirm the issue. It does not depend on display type. Same for block or page display. Any ideas, patches?
Comment #4
le72Comment #5
osab CreditAttribution: osab as a volunteer and at AnyforSoft, Drupal Ukraine Community for AnyforSoft commentedLooks like need to be fixed parameter $force_int for unpackArgumentValue().
Result of local testing attached.
Despite that, the patch is working, but maybe need to check how to fix properly $this->definition['numeric'], now it has TRUE value even for the string context filter?
Comment #6
osab CreditAttribution: osab as a volunteer and at AnyforSoft, Drupal Ukraine Community for AnyforSoft commentedComment #7
osab CreditAttribution: osab as a volunteer and at AnyforSoft, Drupal Ukraine Community for AnyforSoft commentedadded screenshot with testing OR with AND condition in the contextual filter.
Comment #8
codersukanta CreditAttribution: codersukanta at Srijan | A Material+ Company for Drupal India Association commentedThe issue was with the Roleid plugin definition. Previously role id is used to be a numeric value but it's not numeric anymore.
Comment #9
atul4drupal CreditAttribution: atul4drupal commentedThe patch at #8 worked perfectly for me.
Its RTBC 1 for the patch at #8.
Let more people give it a try and see for themselves before moving issue status to RTBC.
Comment #10
LendudeNice find, and thanks for the work on this.
You should never (hardly ever?) have to use an alter hook inside core, since we should just be supplying the correct data to begin with.
In this case, the change should be made in
\Drupal\user\UserViewsData
That currently says:
So that 'numeric' seems wrong, and we should change it there.
Also, this needs an automated test.
Comment #11
codersukanta CreditAttribution: codersukanta at Srijan | A Material+ Company for Drupal India Association commentedThanks, @Lendude
I will create a new patch for this.
Comment #12
codersukanta CreditAttribution: codersukanta at Srijan | A Material+ Company for Drupal India Association commentedThe issue was with the Roleid plugin definition. Previously role id is used to be a numeric value but it's not numeric anymore.
Here is the updated patch.
Comment #13
LendudeIf anything, we should just leave this out and not set it too FALSE.
But looking at this some more, the better fix would probably be to not have \Drupal\user\Plugin\views\argument\RolesRid extend ManyToOne but use \Drupal\views\Plugin\views\argument\StringArgument and 'many to one' set to TRUE. But that might be too big of a change?
But don't bother rolling any of that into a patch unless we add some test coverage first, because there might be some details we are overlooking here.
This handler only has a Unit test, I feel we need a functional test for this
Comment #15
codersukanta CreditAttribution: codersukanta at Srijan | A Material+ Company for Drupal India Association commentedReplacing ManyToOne with StringArgument is working fine except the AND(role1,role2) condition.
Passing role as (role1,role2) should work as AND statement in the query however its been treated as OR statement. Looks like the AND clause is completely missing.
The codes block from the query function in StringArgument class at line number 239 is causing the issue.
Passing more than one arguments in contextual filter always replace $operator with IN statement. I am strugling to find a way to have AND clause added here any help or direction will be appreciated.
Comment #16
mohit_aghera CreditAttribution: mohit_aghera at QED42 commented@Lendude
Adding a few functional test cases to evaluate if the patch works with all the scenarios. Patch is passing on local.
I think I can review a few things in that direction.
Besides, I think we can switch the issue to 9.2.x branch.
Comment #19
SpokjeAbove test failures where caused by a broken HEAD. This was fixed in #3207086: [HEAD BROKEN] Consistent failure in MonthDatePluginTest. Ordered retest and put this issue back to RTBC per #16.
Comment #21
mohit_aghera CreditAttribution: mohit_aghera at QED42 commentedComment #22
SpokjeComment #24
dmgaye96 CreditAttribution: dmgaye96 commentedHello I want to display like this image with the contextual filters of drupal but I can not display the title description and number of module of each course at once
Comment #25
le72#16 looks great 👍🏻
Comment #26
Lendude@mohit_aghera great stuff!
The fix seems to do the trick, so disregard my comment in #13, lets go with this.
Any reason to add and use the entity reference display? Or could we just use the default display?
maybe quote 'allow multiple values'?
In all these cases we want to check for all users. We need a pageTextNotContains for the users we expect to be hidden. The way it is setup now, it could be showing all the users in every case and the test would still pass
Comment #27
mohit_aghera CreditAttribution: mohit_aghera at QED42 commentedThanks for the review @Lendude.
1. I think "entity_reference" display might have came through when I cloned some views while writing test case.
It is not necessary. Removed it.
Though there is a difference in a format like "Entity Reference list" won't be available in the default view. However, we can safely ignore it because title will still be displayed and we want to compare the title only, irrespective of format.
Test cases are still passing with relevant changes.
2. Fixed the code
3. Added assertions to validate that titles shouldn't exist which doesn't specify criteria.
Comment #28
LendudeLooks great, thanks!
Comment #29
alexpottCommitted and pushed eb2ed2340f to 9.3.x and 392faadb1d to 9.2.x. Thanks!
Nice to have this fixed and tested.