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
Issue fork viewsreference-3591361
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
Comment #3
damienmckennaComment #4
dalinComment #5
scott_euser commentedThanks for the work on this! Doesn't seem to fit the criteria for major.
Comment #6
hartsak commentedI 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!
Comment #7
philyMR!106 works for me using viewsreference as a paragraphs field.
As a side note,
core/modules/views/src/ContextualLinksHelper.phpfile has been updated in 11.4.0 release so it now statesassert(in_array($location, ['block', 'page', 'view', 'exposed_filter'], TRUE));Comment #8
anybody@scott_euser
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
Comment #9
anybodyPS: Details on runtime conversions and server configuration can be found here:
https://www.drupal.org/docs/develop/drupal-apis/runtime-assertions#s-con...
Comment #12
grevil commentedAdded an appropriate test. Unfortunately, the "TEST ONLY" pipeline will probably also succeed since the CI Runner runs the test with:
So it will also succeed. But still better then no test...
Comment #13
anybodyNo, it works as expected, LGTM. What do you think @scott_euser? I think a new release should then get tagged as of #8?
Comment #14
scott_euser commentedThanks! 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
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!
Comment #15
anybodyTest 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?
Comment #16
anybody@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!
Comment #17
anybodyPS: New stable release would be great then.
Comment #18
scott_euser commentedI 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 :)
Comment #22
scott_euser commentedThanks everyone! Will leave #14 unanswered its not deal-breaker