What are the steps required to reproduce the bug?
See /core/modules/views/src/Element/View.php
It can be reproduced by opening a page with a View (in a block), deleting the View, or (easier) by adding some extra characters to view name ($element['#name']
) in $view = Views::getView($element['#name']);
line, to force an error (eg $element['#name'].'XXX'
).
What behaviour were you expecting?
Normal View output
What happened instead?
You get an error: Fatal error: Unsupported operand types in ...../core/modules/views/src/Element/View.php on line 49
This is could be more helpful.
Solution
Test for null return in $view and add a message like 'drupal_set_message(t('View '.$element['#name'].', used on this page, is missing.'), 'error');
', and return.
(see patch)
Comment | File | Size | Author |
---|---|---|---|
#28 | interdiff-2868258-22-28.txt | 2.77 KB | joegraduate |
#28 | 2868258-28.patch | 2.26 KB | joegraduate |
#5 | 2868258-5.patch | 1.9 KB | Lendude |
#5 | interdiff-2868258-3-5.txt | 1.78 KB | Lendude |
#3 | 2868258-3.patch | 1.96 KB | Lendude |
Issue fork drupal-2868258
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 #2
dawehnerI'm wondering whether it would be better to actually throw an exception ...
Comment #3
LendudeYeah throwing an exception makes sense to me. So maybe something like this?
Comment #4
dawehner"Data" always sounds super generic / without any meaning
Nice test
Comment #5
LendudeAh yes 'naming things' :)
This any better?
Comment #6
dawehner+1
Comment #7
alexpottHow about including the invalid name in the exception? Would seem helpful - no?
Comment #13
jonathanshawThis one should be really really easy to fix :)
Comment #14
xjmNormally, adding a new exception would be a minor-only change. However, given that there is currently a fatal error in HEAD, a new exception is not any more disruptive than that.
Also, given that this causes a WSOD and has steps to reproduce via the user interface, it can be considered major, and is potentially eligible for backport to 8.9.x still for that reason.
An updated patch for #7 and the reroll can also be tested against 9.2.x and 9.1.x if it applies there as well. Otherwise, we can create separate patches.
Thank you!
Comment #15
joegraduateGoing to work on a reroll/merge request and try to incorporate the suggestion from #7.
Comment #16
joegraduateThis is a re-roll of #5 that incorporates the suggestion in #7. This should apply cleanly to 8.9.x, 9.1.x, and 9.2.x.
Comment #17
joegraduateFixed (existing) coding standards issues in #16.
Comment #19
joegraduateCreated merge request from #17 to make tugboat live preview available. This should be ready for review/testing.
Comment #21
joegraduateComment #22
joegraduateUpdated patch with latest changes in MR branch:
- Fixed template literal in exception message.
- Replaced deprecated test method.
- Moved exception to Drupal\views\Exception namespace.
- Moved new test into existing ViewElementTest kernel test class.
Tests should pass and this should really be ready for review now.
Comment #23
jonathanshawComment #24
Jons CreditAttribution: Jons as a volunteer commentedthanks all!
Comment #26
LendudeUnrelated fail
Comment #27
larowlanI think the description here has too much knowledge of when it is thrown. Which would prevent us from reusing this exception elsewhere.
Suggest that we rename the class to ViewRenderElementException and make the the docblock say
'Defines an exception for an invalid View render element' or similar
Then we can re-use this exception later for other uses cases such as when the display name is wrong or the arguments.
Thoughts?
I don't agree with this being a major bug, so dropping the priority, its a developer nuisance more than anything - I would even go close to marking it as minor.
Comment #28
joegraduateUpdated patch with @larowlan's suggestions from #27.
Comment #29
jonathanshawRTBC if bot agrees.
Comment #30
larowlanRevisiting earlier comments I see that xjm classed this as major, so re-instating that.
On that basis this qualifies for backport, but I think the ship has sailed for 8.9.
Committed 1ab0f48 and pushed to 9.3.x. Thanks!
Backported to 9.2 and 9.1
Thanks everyone involved