Issue #1898060 by steveoliver, taslett, jenlampton | c4rl: Convert dblog module to Twig.
Task
Use Twig instead of PHPTemplate
Twig sandbox: http://drupal.org/sandbox/pixelmord/1750250
Remaining
* replace all tpl.php files with .html.twig equivalents
* replace all theme functions with .html.twig equivalent templates
* add new preprocess functions for the .html.twig equivalent templates
* update all hook_theme definitions
To test this code...
1) Go to the db log page (admin/reports/dblog) to see links, rendered via dblog-message.html.twig
2) Click on any of the links on the on the dblog page to see the full message, rendered via dblog-message.html.twig
Related Issues
#1757550: [Meta] Convert core theme functions to Twig templates
#1956806: Fix DbLogController::overview() and topLogMessages() logic and provide a formatMessage() method
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | core-remove_theme_funcs_from_dblog-1898060-24.patch | 4.9 KB | jenlampton |
| #24 | interdiff.txt | 784 bytes | jenlampton |
| #22 | core-remove_theme_funcs_from_dblog-1898060-22.patch | 4.87 KB | jenlampton |
| #15 | 1898060-15.patch | 2.51 KB | star-szr |
| #15 | interdiff.txt | 680 bytes | star-szr |
Comments
Comment #1
c4rl commentedTagging
Comment #2
taslett commentedComment #3
taslett commentedComment #4
fabianx commentedThis one is tricky to see, but here you can use:
url() instead and use
<a href="{{ link_url }}">{{ link_text }}</a>in the template.
Then at least the template would be useful.
Probably it could be deprecated and be a derivative of theme_link later, so lets add a comment with @todo as well for that.
Thanks for your work!
Comment #5
taslett commentedHi Fabianx,
The dblog-message.html.twig template is used when the full message is displayed, after clicking the link in the log. So we will need a conditional statement either in the preprocess function or the template. I think that will make the @todo irrelevant.
This is what I am looking at currently.
Comment #6
taslett commentedUsing url() in the preprocess function and the conditional in the html.twig file.
Comment #7
star-szrThanks @taslett! Minor nitpicks ahead :)
This line shouldn't be changed, the 'array' should be kept.
Also, dblog-message.html.twig needs a newline at the end of the file.
Comment #8
taslett commentedThanks Cottser,
Not sure why I removed the array.
Didn't realize the html.twig file needed a newline at the end of the file should we add that to the twig coding standards page #1823416 ?
Comment #9
star-szrThanks @taslett! I should have mentioned this but interdiffs are helpful too :)
As for the newline, that's covered by http://drupal.org/coding-standards#indenting, no need for a Twig-specific standard there.
Comment #10
taslett commentedAdding interdiff for comment 8 above.
Comment #11
jenlamptonThis one looks great! Thank you both for working on it :)
This patch includes a few very minor changes.
1) Simpler variable names: text and url instead of link_text and link_url.
2) Also included these variables under "Available variables" in the template docblock.
Comment #12
chx commentedI think this is the first Twig template conversion patch I happen to RTBC and it's hard to describe the joy i feel over seeing
things like this.
Comment #13
joelpittetLooks great, nice work taslett
Comment #14
fabianx commented+1 for RTBC
Comment #14.0
fabianx commentedadd how to test this code
Comment #15
star-szrMinor comment nitpick in line with the variable changes in #11, and added commit message per git blame, couldn't find any issues in the sandbox.
One thing to note before committing is that we haven't yet reached consensus on the standards for preprocess documentation: #1913208: [policy] Standardize template preprocess function documentation
Comment #16
jenlamptonWe're going to need to update the rest of core to match the new coding standards for preprocess, so I don't think that should block a commit here.
Otherwise, looks great! :)
Comment #17
star-szr#16/@jenlampton - Agreed, patch looks good!
Comment #18
dries commented- Wouldn't be cleaner if we always had 'message' instead of having 'message' and 'text'.
- When do we have log messages that don't provide a URL? I don't think that actually happens.
Comment #19
webchickYeah, I looked at Drupal.org's admin/reports/dblog (D6), as well as webchick.net's (D7).
While I didn't go through every single page, I went through quite a few of them, and never found an instance of a dblog message without a URL linking to the more specific info. So it seems like we could remove support for that feature without making anyone cry.
However, if we did that, then the Twig template just becomes:
Which I would think is exactly what theme_link() (or its ilk) would be doing.
So my question would be, do we actually need this template file at all, if we just made the wlid part of the watchdog API?
Comment #20
webchickComment #21
jenlamptonOn admin/reports/dblog the link is always printed.
When you click that link, you are taken to admin/reports/event/N where the {{ message }} is printed instead.
If we delete message then we'll never see the longer version.
I will give this a re-roll and try to eliminate the theme function entirely.
Comment #22
jenlamptonOkay, here's a more sane approach with no theme functions at all. Let's see if there were tests that now fail :)
Comment #24
jenlamptonThis one prevents the double escaping, should pass tests.
Comment #25
jhedstromTested this manually, and it works as before, both for messages with variables and without.
Comment #26
webchickCommitted and pushed to 8.x. Yeah!
While this represents an API change, I'm thinking it's going to be way too annoying to track each of these individually, so we should just talk about it in the "meta" change notice about converting things to Twig.
Comment #27
webchickComment #29
sunIf a query result row does not have a ->message and ->variables for any reason, then $message contains the $message of the last row.
Could we have added a dblog_format_message() helper function instead of duplicating the same code in multiple places?
Comment #30
star-szrThanks @sun! To follow up on the feedback in #29, I created #1956806: Fix DbLogController::overview() and topLogMessages() logic and provide a formatMessage() method.
Comment #30.0
star-szrAdd commit message.
Comment #31
sunI re-opened this issue in #29, because I already predicted that no one would care if it would be moved to a new issue. That's what happened now.
@jenlampton, @taslett, @Cottser: Any chance you can follow up with necessary fixes on #1956806: Fix DbLogController::overview() and topLogMessages() logic and provide a formatMessage() method?
Comment #32
star-szr@sun - I don't think it's that we don't care, it's that we've been a bit busy working on the 80+ other Twig conversion issues. I'd be happy to work on the follow-up and I've just assigned it to myself.
Comment #33.0
(not verified) commentedAdd follow-up issue to summary