Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Twig_debug output is very hot right now and a big reason is that many functions have been converted to templates.
Still the output can be very useful already. Also this can be useful to ease the Drupal 7 > Drupal 8 path by having available this little gem feature already in Drupal 7.
Proposed resolution
Port over the twig debug output and make it available for D7 using theme_debug variable.
Remaining tasks
None.
User interface changes
None.
API changes
- API addition: theme_hook_original is set as in D8
- API addition of _theme_render_template_debug function - internal
New variable:
theme_debug => TRUE / FALSE, defaults to FALSE
Comment | File | Size | Author |
---|---|---|---|
#34 | 2307505-34-followup.patch | 1.53 KB | David_Rothstein |
#18 | interdiff.txt | 523 bytes | star-szr |
#18 | 2307505-18.patch | 8.25 KB | star-szr |
#17 | interdiff.txt | 2.09 KB | star-szr |
#17 | 2307505-17.patch | 8.24 KB | star-szr |
Comments
Comment #1
Fabianx CreditAttribution: Fabianx commentedComment #2
David_Rothstein CreditAttribution: David_Rothstein commentedSomething like this seems safe to go in to Drupal 7.
Would it be better to do it more like this though (to avoid an extra function call for production sites)?
Comment #3
Fabianx CreditAttribution: Fabianx commentedThat seems like a great suggestion!
Comment #4
star-szrThis would be amazing.
Comment #5
star-szrGoing to work on this in the near future :)
Comment #6
Fabianx CreditAttribution: Fabianx commentedThanks, Cottser :)
Comment #7
star-szrThis implements #2 and backports the tests. I couldn't figure out how to get drupal_render() to use test_theme so there are a couple drupalGet()s thrown in.
Comment #10
Fabianx CreditAttribution: Fabianx commentedI now it was my idea, but if we are gonna run with this for any engine, we should probably also pass the extension in and its trivial to do so.
I think we can remove this if code now :)
The debug markup test still fails, no idea why though.
Comment #11
star-szrOops on #2, and I agree on #1. I can make those changes a bit later today. Thanks @Fabianx!
The tests definitely pass locally for me, via UI and run-tests.sh. I started chucking some patches up on #2338069: Ignore: patch testing issue for 2307505 to see if anything would stick. My guess at this point is that testbot is not seeing the test_theme template in the registry.
Comment #12
star-szrThis addresses #10 and takes out a drupal_theme_rebuild() from the test.
Comment #14
star-szrSo... I forgot to
git add
the new testing template I added. This should be green now :)Comment #15
Fabianx CreditAttribution: Fabianx commentedVery little nit:
- Mark Carver asked for the variable to be only called "theme_debug" to more closely match "twig_debug" in D8.
Once that is done - if we agree this should be done - this is RTBC :).
Great work!
Comment #16
star-szrSure, I agree!
Comment #17
star-szrHere's that change.
Comment #18
star-szrAnd while we're at it, here's the return type for _theme_render_template_debug :)
Cancelling the last test.
Comment #20
Fabianx CreditAttribution: Fabianx commentedRTBC, great work!
Comment #21
joelpittetDemo'd this patch in a lightning talk in VanDUG! And have been using it in my sites.
Comment #24
star-szrComment #27
dcam CreditAttribution: dcam commentedComment #30
star-szrComment #31
David_Rothstein CreditAttribution: David_Rothstein commentedCommitted to 7.x - thanks!
I added a note about this to CHANGELOG.txt, but it might be good to document somewhere else too (maybe a change notification)?
Question:
Would it be a good idea to check_plain() this (maybe some of the other output too, but especially this one)? I'm not too worried about it is since this is intended for developers anyway (not for live sites) but I am thinking that theme suggestion names come from all over the place; might be good to be safe.
I made two small fixes on commit, by the way:
Comment #33
David_Rothstein CreditAttribution: David_Rothstein commentedComment #34
David_Rothstein CreditAttribution: David_Rothstein commentedThinking about this a little more I think we do need the check_plain(). It's intended for HTML output, so regardless of security considerations or not I think it needs that. Would be safer to just do it.
Any thoughts on the attached patch?
It's possible Drupal 8 needs something similar, but would be useful to get this in for the upcoming D7 release since it's going out to sites soon.
Comment #35
Fabianx CreditAttribution: Fabianx commentedRTBC, I totally agree, e.g. for page.tpl.php, we use the create theme suggestions functions (whatever that is called), which IIRC would then create the -- based on the page arguments. That should be properly escaped, but this is safer for sure and because its in a debug path, lets just do it.
Thanks so much for accepting the patch!
Comment #36
David_Rothstein CreditAttribution: David_Rothstein commentedCommitted to 7.x - thanks!
Thank you for working on the patch :)
As for documentation, I added a bit more info to the CHANGELOG.txt entry for this (which will also go into the release notes). If anyone wants to create a formal change record for this also, feel free... but it's not strictly necessary or anything.
Comment #38
redndahead CreditAttribution: redndahead commentedIs there a way for other modules to alter the $output variable to add on their own items? I could see other modules possibly having data that could be important to show.
Comment #39
star-szr@redndahead - Not as is, it's meant to just output relevant information coming from the theme system only.
Really happy to see this in, and I agree about the check_plain. Here's an issue for D8 to consider something similar: #2369781: Ensure twig_debug output has needed sanitization