Problem/Motivation

AssertionError: assert(in_array($location, ['block', 'page', 'view'], TRUE)) in assert() (line 79 of core/modules/views/src/ContextualLinksHelper.php).

In Drupal 11.4, ContextualLinksHelper::addLinks() gained a strict assertion requiring the $location argument to be one of 'block', 'page', or 'view'. The ViewsReferenceFieldFormatter calls views_add_contextual_links() passing $render_array['#view_display_plugin_id'] directly as the location, which works for block and page displays but fails for any other display type (e.g. embed), triggering an AssertionError and a fatal error on any page that renders a viewsreference field using an embed display.

Steps to reproduce

Install viewsreference with Drupal 11.4, witness the error.

Proposed resolution

Before passing the display plugin ID to views_add_contextual_links(), map it to a valid location: pass it through unchanged if it is already one of the three allowed values, otherwise fall back to 'view'.

Remaining tasks

User interface changes

API changes

Data model changes

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:

Comments

ltrain created an issue. See original summary.

damienmckenna’s picture

Version: 8.x-2.0-beta12 » 8.x-2.x-dev
Status: Active » Needs review
dalin’s picture

Priority: Normal » Major
scott_euser’s picture

Priority: Major » Normal
Status: Needs review » Needs work

Thanks for the work on this! Doesn't seem to fit the criteria for major.

  1. Looks like phpcs errors
  2. Can we add test coverage please, module is used too heavily to not so that
  3. Please can you provide more detailed steps, if I understand right it must be configured and used in a particular way yet that isn't indicated in issue summary how
hartsak’s picture

I had the exactly same issue after updating to 11.4

I tested the patch and it fixes the problem for me.
The OP mentioned something about how to reproduce the issue: "triggering an AssertionError and a fatal error on any page that renders a viewsreference field using an embed display."

I can try to provide a bit more detailed steps here (for Drupal 11.4 and Viewsreference 2.0.0-beta12):
- Create a view and add an "Embed" type display to it
- Create a viewsreference field to a node
- Make sure "Embed" is one of the allowed types in "View display plugins to allow"
- If you are using "Preselect View Options", make sure your new view with the Embed display is also one of the selected views
- Create a node and select your view with the Embed display in the viewsreference field
- Fatal error when viewing the node page

Hope this helps!

phily’s picture

MR!106 works for me using viewsreference as a paragraphs field.

As a side note, core/modules/views/src/ContextualLinksHelper.php file has been updated in 11.4.0 release so it now states
assert(in_array($location, ['block', 'page', 'view', 'exposed_filter'], TRUE));

anybody’s picture

Issue tags: +Needs tests

@scott_euser

Thanks for the work on this! Doesn't seem to fit the criteria for major.

depends on having assertions enabled (ini_set('zend.assertions', 0);). I agree that typically it should be disabled in production, but not all hosters do this.

So if not, you're getting a WSOD currently, which is major. You decide. IMHO at least 'in mind' it should be major with Drupal 11.4 released.

Adding Needs tests as of #5

anybody’s picture

PS: Details on runtime conversions and server configuration can be found here:
https://www.drupal.org/docs/develop/drupal-apis/runtime-assertions#s-con...

grevil made their first commit to this issue’s fork.

grevil’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Added an appropriate test. Unfortunately, the "TEST ONLY" pipeline will probably also succeed since the CI Runner runs the test with:

Drupal installed version: 11.3.12

So it will also succeed. But still better then no test...

anybody’s picture

Status: Needs review » Reviewed & tested by the community

No, it works as expected, LGTM. What do you think @scott_euser? I think a new release should then get tagged as of #8?

scott_euser’s picture

Priority: Normal » Major

Thanks! Sounds like its more common given the flurry of activity, happy to bump it back up.

On the tests
No worries, I can run the test locally in 11.4 to verify np, we can mark test as skipped <= 11.4 maybe then? Something like

if (floatval(\Drupal::VERSION) < 11.4) {
  $this->markTestSkipped("This test covers 11.4 and higher since the issue this covers does not occur in 11.3.");
}

But it does look like the test failed when you did test only?

Manual steps to test
Steps in the summary are still a bit unclear. It sounds like create a View with display type 'Embed', make use of that in a Viewsreference field, have contextual module enabled, and be on 11.4, then experience the error? Just so its clear when I come to manually final test on it that I don't need to struggle to figure it out :)

Phpcs
Minor phpcs looks like still being introduced here.

Otherwise yeah happy to make a quick release of this if I can just verify it myself locally manually once too. Thanks all!

anybody’s picture

Test results seem as expected to me, I also ran the Test-only in the regular branch and it failed as expected? Or am I getting the results wrong?

anybody’s picture

@scott_euser any chance to merge this? We've now experienced this in several projects upgraded to Drupal 11.4 with WSODs on different providers.

I can definitely confirm the MR fixes it!

anybody’s picture

PS: New stable release would be great then.

scott_euser’s picture

Status: Reviewed & tested by the community » Needs work

I was waiting for my question in #14 to be answered + phpcs (also noted there) to be resolved. Will set to needs work to be clear. Thanks :)

idebr made their first commit to this issue’s fork.

  • scott_euser committed 0afb4756 on 8.x-2.x authored by ltrain
    fix: #3591361 AssertionError in ContextualLinksHelper when display...

scott_euser changed the visibility of the branch 3591361-assertionerror-in-contextuallinkshelper--TEST-ONLY to hidden.

scott_euser’s picture

Status: Needs work » Fixed

Thanks everyone! Will leave #14 unanswered its not deal-breaker

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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