When creating a view that displays a summary when contextual filter is not present and a base path is set, the resulting page generates a fatal error for using $this when not in an object context which comes from line 280 of views.theme.inc [$tokens = $this->getArgumentTokens()]. There are actually 4 references to "$this" in the file and I'm assuming that the others will generate the same fatal error.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

r0nn1ef created an issue. See original summary.

cilefen’s picture

Priority: Normal » Major
Issue tags: -views

Nice find. There is not a class to be seen in this file. I am bumping this to Major priority.

cilefen’s picture

Version: 8.0.5 » 8.1.x-dev
cilefen’s picture

Title: Fatal error: $this when not in object context » Fatal error: $this when not in object context in views.theme.inc.
r0nn1ef’s picture

Issue summary: View changes
cilefen’s picture

Status: Active » Needs work
Issue tags: +Needs tests
FileSize
1.54 KB

This is just part of it. viewsTokenReplace() is a protected method on a views plugin. This needs test coverage.

cilefen’s picture

Status: Needs work » Needs review
FileSize
1.78 KB
r0nn1ef’s picture

Thanks for the quick turn around on this. I've applied the patch in #7 and no longer receive the fatal error.

Lendude’s picture

Status: Needs review » Needs work

Fix looks good, setting to 'needs work' for the tests.

andypost’s picture

A test view to reproduce the issue
EDIT https://gist.github.com/andypost/ccb9fbf00298f49388a4

Lendude’s picture

Here are some tests for this, as the tests will show, the fix in #7 solves the fatal but the extra arguments are not added to the base path in the summary, so all links in the summary just point to the base path.

The last submitted patch, 11: summary_fatal-2685021-11-TEST_ONLY.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 11: summary_fatal-2685021-11.patch, failed testing.

Lendude’s picture

Status: Needs work » Needs review
FileSize
7.58 KB

No idea if this is the right way to do this, but it works and turns the test green locally.

Added more tests and redid the ones in #11

andypost’s picture

Status: Needs review » Needs work

Suppose <front> should be a route fallback

Lendude’s picture

Status: Needs work » Needs review
FileSize
795 bytes
7.58 KB

@andypost good point, updated.

Lendude’s picture

Bleh, forgot to update the comment

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Looks ready for me

dawehner’s picture

I always really like if we break things, and then add test coverage due to that.

+++ b/core/modules/views/views.theme.inc
@@ -277,11 +277,30 @@ function template_preprocess_views_view_summary(&$variables) {
+      /** @var \Drupal\Core\Url $url */
       $url = Url::fromUserInput('/' . $base_path);

@@ -346,11 +366,28 @@ function template_preprocess_views_view_summary_unformatted(&$variables) {
+      /** @var \Drupal\Core\Url $url */
       $url = Url::fromUserInput('/' . $base_path);

Nitpick: I don't see why you would have to specify this type here, but nevermind.

Lendude’s picture

Clean up per #19, no idea why I stuck that in.

dawehner’s picture

Okay, cool!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 6748315 and pushed to 8.0.x, 8.1.x and 8.2.x. Thanks!

  • alexpott committed 1d13c5f on 8.2.x
    Issue #2685021 by Lendude, cilefen, r0nn1ef, andypost: Fatal error: $...

  • alexpott committed 6748315 on 8.0.x
    Issue #2685021 by Lendude, cilefen, r0nn1ef, andypost: Fatal error: $...
Lendude’s picture

Status: Needs work » Fixed

Uhh no idea how this got to 'needs work' again, back to fixed.

Status: Fixed » Closed (fixed)

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

lamp5’s picture

Any plans to fix this on 8.3.x ??