Problem/Motivation
This came up while working on #2369981: Not found templates are displayed literally instead of throwing an Exception due to string loader.
When twig_render_template() catches a \Twig_Error_Loader exception (for example when a Twig template is not found), the $output variable and its array keys are not yet defined, but twig_render_template() carries on trying to manipulate them and you get some excessive notices:
Notice: Undefined variable: output in twig_render_template() (line 66 of core/themes/engines/twig/twig.engine).
Notice: Undefined index: debug_prefix in twig_render_template() (line 66 of core/themes/engines/twig/twig.engine).
Notice: Undefined index: debug_info in twig_render_template() (line 101 of core/themes/engines/twig/twig.engine).
Notice: Undefined index: debug_suffix in twig_render_template() (line 104 of core/themes/engines/twig/twig.engine).
These notices don't affect functionality at all, but they are annoying.
Proposed resolution
Minor internal refactor: Initialize $output and its array keys early so that only the actual \Twig_Error_Loader exception (via drupal_set_message()
) is shown.
Remaining tasks
PatchTests (no test additions/changes made, see #4)- Review
Beta phase evaluation
Issue category | Bug because the patch fixes PHP notices. |
---|---|
Issue priority | Normal, just a bug fix for annoying PHP notices when Twig templates are not found. |
Prioritized changes | Bug fix |
Disruption | Not disruptive at all, minor internal refactor to remove PHP notices. |
User interface changes
Gets rid of ugly notices when, for example, a Twig template is not found.
API changes
n/a
Comment | File | Size | Author |
---|---|---|---|
#3 | interdiff.txt | 782 bytes | star-szr |
#3 | 2430981-3.patch | 972 bytes | star-szr |
Comments
Comment #1
star-szrInitial patch.
Comment #2
joelpittetNice catch, little nit and I don't think this needs tests it's not changing the functionality just initializing the variables but your call:
Can you remove the space alignment here?
Comment #3
star-szrPondering a test for this but you are probably right. Here is that change + short array syntax :) Interdiff is probably not too useful in this case.
Comment #4
star-szrComing up short on how to test this and don't want to spend all night on it. The closest I got was a thought to try and test twig_debug output but PHP powers through all the undefined arrays and strings and the twig_debug output still gets rendered in the end in the exact same way.
Comment #5
star-szrUpdated the issue summary, added beta evaluation.
Comment #6
Fabianx CreditAttribution: Fabianx commentedRTBC, looks good.
Comment #7
alexpottThis issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed f153619 and pushed to 8.0.x. Thanks!