Problem/Motivation

When adding the Roles Contextual filter to a view with users, it will give handler broken/missing.

Work done on user roles in #2248977 changed how user roles are handled, and broke the handling by Views.

Proposed resolution

Fix it.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue priority Not critical because it's not a much used feature.
Unfrozen changes Unfrozen because it only changes code necessary to fix a bug.
Prioritized changes The main goal of this issue is usability.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Lendude’s picture

Status: Needs review » Needs work
dawehner’s picture

+++ b/core/modules/user/src/Plugin/views/argument/RolesRid.php
@@ -17,7 +17,7 @@
- * @ViewsArgument("user__roles_rid")
+ * @ViewsArgument("user__roles_target_id")
  */
 class RolesRid extends ManyToOne {

Seriously, who reviewed that, before it got in :( ... I would vote to rename it back to "user_roles" and be done with it.

Lendude’s picture

Problem is that even with the name change this still doesn't work. The name change might not actually do anything, this it all a bit beyond me really. Just wanted to report it and maybe point it in the direction where I thought the break might be.

dawehner’s picture

Issue tags: +Needs tests

Ah mh, well at least let's ensure that we add tests later

Lendude’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
2.54 KB

Added some tests that fail, but I recon should be green when this works as intended.

- Test that the right handler is used (returns the Broken handler at the moment)
- Test that the argument filters the result set (doesn't at the moment)

If I combine the tests with the 'fix', the test results in a fatal error:
Argument 4 passed to Drupal\user\Plugin\views\argument\RolesRid::__construct() must implement interface Drupal\Core\Entity\EntityManagerInterface, none given

I'll look into that next.....

Status: Needs review » Needs work

The last submitted patch, 5: 2405481-5-SHOULDFAIL.patch, failed testing.

Lendude’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
3.87 KB

Well, I actually think I got it.

Updated the tests a bit to test for the right handler. Stuck with the name user__roles_rid because that seemed to be used in some unit tests for this handler as well.

dawehner’s picture

  1. +++ b/core/modules/user/src/Plugin/views/argument/RolesRid.php
    @@ -50,7 +50,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
       public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    -    return parent::create($container, $configuration, $plugin_id, $plugin_definition, $container->get('entity.manager'));
    +    return new static($configuration, $plugin_id, $plugin_definition, $container->get('entity.manager'));
       }
    

    Ha!

  2. +++ b/core/modules/user/src/Tests/Views/HandlerArgumentUserRoleTest.php
    @@ -0,0 +1,46 @@
    +  /**
    +   * @file
    +   * Contains \Drupal\user\Tests\Views\HandlerArgumentUserRoleTest.
    +   */
    

    Let's remove the indentation here

  3. +++ b/core/modules/user/src/Tests/Views/HandlerArgumentUserRoleTest.php
    @@ -0,0 +1,46 @@
    +/**
    + * Tests the handler of the user: role Argument.
    + *
    + * @group user
    + */
    +class HandlerArgumentUserRoleTest extends UserTestBase {
    +
    

    It would be nice to have a @see to the actual class.

  4. +++ b/core/modules/user/src/Tests/Views/HandlerArgumentUserRoleTest.php
    @@ -0,0 +1,46 @@
    +  /**
    +   * Tests the user: role argument.
    +   */
    +  public function testArgumentTitle() {
    

    Okay fine, and helpful, we check the execution, but we don't check the argument title, as the method kind of implies.

  5. +++ b/core/modules/user/src/UserViewsData.php
    @@ -306,7 +306,7 @@ public function getViewsData() {
    -        'id' => 'user__roles_target_id',
    +        'id' => 'user__roles_rid',
    

    Its still sad to have such a plugin ID. If you look at the existing code in RolesRid nothing of that is tied to the user__roles table. It would be nice to name it 'user_roles' so, its a generic handler, so let's name it generic.

Lendude’s picture

Issue summary: View changes
FileSize
2.89 KB
4.82 KB

So, something like this?

Lendude queued 9: 2405481-9.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 9: 2405481-9.patch, failed testing.

Lendude’s picture

FileSize
4.72 KB

Rerolled.

Lendude’s picture

Status: Needs work » Needs review

Lendude queued 12: 2405481-12.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 12: 2405481-12.patch, failed testing.

Lendude’s picture

Status: Needs work » Closed (fixed)
jibran’s picture

Status: Closed (fixed) » Closed (duplicate)