@dawehner thinks this might be a duplicate of an existing issue, but I wanted to make sure to document it until we confirm.

Steps to reproduce

  1. Install 8.x Standard.
  2. Create a new view of users with a page display and path users-by-role.
  3. Add a contextual filter for the user role.
    Only local images are allowed.
  4. Go to users-by-role/administrator. You get the fatal:
    Fatal error: Call to a member function label() on a non-object in /Applications/MAMP/htdocs/d8git/core/modules/user/lib/Drupal/user/Plugin/views/argument/RolesRid.php on line 23
Files: 
CommentFileSizeAuthor
#20 views-role-contextual-filter-1995868-19-FAIL.patch6.23 KBxjm
FAILED: [[SimpleTest]]: [MySQL] Failed to run tests: PHP Fatal error encountered during run_tests.sh. See review log for details..
[ View ]
#20 views-role-contextual-filter-1995868-19.patch8.64 KBxjm
PASSED: [[SimpleTest]]: [MySQL] 55,528 pass(es).
[ View ]
#19 views-role-contextual-filter-1995868-19.patch8.64 KBxjm
PASSED: [[SimpleTest]]: [MySQL] 55,739 pass(es).
[ View ]
#19 interdiff-1995868.txt2.87 KBxjm
#16 drupal-1995868-16.patch8.58 KBdawehner
PASSED: [[SimpleTest]]: [MySQL] 55,990 pass(es).
[ View ]
#16 interdiff.txt1.39 KBdawehner
#14 drupal-1995868-14.patch8.39 KBdawehner
PASSED: [[SimpleTest]]: [MySQL] 56,028 pass(es).
[ View ]
#14 interdiff.txt1.96 KBdawehner
#11 drupal-1995868-11.patch8.16 KBdawehner
PASSED: [[SimpleTest]]: [MySQL] 56,020 pass(es).
[ View ]
#9 Role-Contextual-Filter-before1.png49.37 KBandymartha
#9 Role-Contextual-Filter-before2.png38.72 KBandymartha
#9 Role-Contextual-Filter-after.png50.94 KBandymartha
#5 drupal-1995868-05-Role-Contextual-Filter-WSOD.patch625 bytesJoshuaRogers
PASSED: [[SimpleTest]]: [MySQL] 56,719 pass(es).
[ View ]
#4 drupal-1995868-04-Role-Contextual-Filter-WSOD.patch627 bytesJoshuaRogers
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch drupal-1995868-04-Role-Contextual-Filter-WSOD.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#2 drupal-1995868-02-role-contextual-filter-wsod.patch601 bytesJoshuaRogers
PASSED: [[SimpleTest]]: [MySQL] 57,411 pass(es).
[ View ]
role_contextual_filter.png16.43 KBxjm

Comments

Would be cool IMO to paste the view yaml into the bug report so we can skip creating the view. Hope we get there one day.

Assigned:Unassigned» JoshuaRogers
Status:Active» Needs review
StatusFileSize
new601 bytes
PASSED: [[SimpleTest]]: [MySQL] 57,411 pass(es).
[ View ]

It looks like the value used in the call to entity_load is an array when it should be a simple value. Additionally, if the value couldn't be found, entity_load returns FALSE, so the call to ->label() was failing in those cases.

Status:Needs review» Needs work

The patch makes it return a boolean, though. I think the code should be something like

<?php
if ($entity = entity_load(...)) {
  return
$entity->label();
}
?>

Status:Needs work» Needs review
StatusFileSize
new627 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch drupal-1995868-04-Role-Contextual-Filter-WSOD.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Good catch! Rerolled.

StatusFileSize
new625 bytes
PASSED: [[SimpleTest]]: [MySQL] 56,719 pass(es).
[ View ]

Changed last return value for clarity.

Status:Needs review» Needs work
Issue tags:-VDC, -Configurables

The last submitted patch, drupal-1995868-05-Role-Contextual-Filter-WSOD.patch, failed testing.

Status:Needs work» Needs review
Issue tags:+VDC, +Configurables

Looks good to me, but I don't know Views enough to RTBC myself.

Status:Needs review» Reviewed & tested by the community
StatusFileSize
new50.94 KB
new38.72 KB
new49.37 KB

On a standard download of Drupal 8, the steps outlined in the issue summary by xjm produced a white screen of death for me. See screenshot.

After applying patch drupal-1995868-05-Role-Contextual-Filter-WSOD.patch from #5 by JoshuaRogers to a fresh Drupal 8 install, the path correctly gave me the view in Drupal instead of the WSOD. See screenshot with no perceived detriment in functionality. Good job!

Role-Contextual-Filter-before1.pngRole-Contextual-Filter-before2.pngRole-Contextual-Filter-after.png

Status:Reviewed & tested by the community» Needs work
Issue tags:+Needs tests

We need a test for this...

Status:Needs work» Needs review
Issue tags:-Needs tests
StatusFileSize
new8.16 KB
PASSED: [[SimpleTest]]: [MySQL] 56,020 pass(es).
[ View ]

Let's phpunit that!

Issue tags:+phpunit

Just a couple of comments about the test as I was chatting with dawehner in irc about it...

+++ b/core/modules/user/tests/Drupal/Tests/user/Views/Argument/RolesRidTest.phpundefined
@@ -0,0 +1,99 @@
+    // NULL forces to disable mocking on any method by default.

I'd prefer a comment here about what we're actually doing, rather than about how PHPUnit behaves, e.g. "Create a stub role storage controller that replaces the attachLoad method."

+++ b/core/modules/user/tests/Drupal/Tests/user/Views/Argument/RolesRidTest.phpundefined
@@ -0,0 +1,99 @@
+
+    $container = new ContainerBuilder();
+    $container->set('plugin.manager.entity', $entity_manager);
+    \Drupal::setContainer($container);

Why is this needed? I thought our PHPUnit tests could be a container-free zone. Wah.

StatusFileSize
new1.96 KB
new8.39 KB
PASSED: [[SimpleTest]]: [MySQL] 56,028 pass(es).
[ View ]

Why is this needed? I thought our PHPUnit tests could be a container-free zone. Wah.

Sadly not at the moment but I think there is no reason to not inject it all the time?

+++ b/core/lib/Drupal/Core/Entity/Entity.phpundefined
@@ -363,7 +363,7 @@ public function createDuplicate() {
-    return entity_get_info($this->entityType);
+    return \Drupal::entityManager()->getDefinition($this->entityType());

Nice!

+++ b/core/modules/user/lib/Drupal/user/Plugin/views/argument/RolesRid.phpundefined
@@ -19,8 +22,46 @@
+   * The role entity storage controller
+   */
+  protected $roleStorageController;

Missing @var

+++ b/core/modules/user/lib/Drupal/user/Plugin/views/argument/RolesRid.phpundefined
@@ -19,8 +22,46 @@
+   * @{inheritdoc}

{@inheritdoc

+++ b/core/tests/Drupal/Tests/UnitTestCase.phpundefined
@@ -7,6 +7,9 @@
+use Drupal\Core\Config\Config;
+use Drupal\Core\Config\ConfigFactory;

Where are these used?

StatusFileSize
new1.39 KB
new8.58 KB
PASSED: [[SimpleTest]]: [MySQL] 55,990 pass(es).
[ View ]

Where are these used?

Ups.

Assigned:JoshuaRogers» Unassigned

Status:Needs review» Reviewed & tested by the community

Thanks, looks great!

StatusFileSize
new2.87 KB
new8.64 KB
PASSED: [[SimpleTest]]: [MySQL] 55,739 pass(es).
[ View ]

Reroll plus some comment cleanup. I also filed a followup: #2015535: Improve instantiation of entity classes and entity controllers.

StatusFileSize
new8.64 KB
PASSED: [[SimpleTest]]: [MySQL] 55,528 pass(es).
[ View ]
new6.23 KB
FAILED: [[SimpleTest]]: [MySQL] Failed to run tests: PHP Fatal error encountered during run_tests.sh. See review log for details..
[ View ]

Just realized there was never a test-only patch uploaded here. Attached should expose the coverage.

Status:Reviewed & tested by the community» Fixed

Committed 5bf482f and pushed to 8.x. Thanks!

Automatically closed -- issue fixed for 2 weeks with no activity.