Follow-up from #1898466: update.module - Convert theme_ functions to Twig.
Convert theme_update_version to update-version.html.twig
Split from #1898466: update.module - Convert theme_ functions to Twig
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | interdiff-2264833-14-17.txt | 886 bytes | l0ke |
| #17 | 2264833-twig-theme_update_version-for-themers-17.patch | 4.18 KB | l0ke |
Comments
Comment #1
joelpittetI've posted two patches here. I want to bring to attention the over abstraction in the theme system and who get's the shaft.
The first one is for developers.
It uses
#theme => linkand#type => tablebut due to it's limitations you must hardcode some markup in the preprocess function to get the desired markup.The interdiff shows the markup differences between the #type table version and the all in the template version.
The second patch is for themers.
There is no process, nor is there a need. All the variables provided to the template are enough to mark them as intended. The template becomes vastly more useful to a themer because they don't have to hunt form markup in some preprocess file and end up having to modify the preprocess and the template files to get the intended effect. That doesn't negate the preprocess's usefulness and if needed they can still have that flexibility but it's cruft. But for every merit there is a drawback. If you plan to change all tables in the system, this one wouldn't get that effect because it's not of
#type => tablenor is it's list of#theme => listand those global changes will have no effect on the theming of these.I come from a background of both sides as I'm sure many of you are the same. You can also see that if we went hard and fast on either way completely we will shoot ourselves(as themers or as developers) in the foot.
I've been thinking about this for the last year but opportunity again came to bring this back to light. The last attempt I did with this concept was less show both sides and just show the themers side but I don't think that was enough. So here I've done the work twice on a fairly simple template. And even if you decide "that shouldn't be a table anyway, why is he complaining, just change it to a div and call it a day". Think a bit down the road for when those types of decisions need to be made and how much effort will it be to change a few tags in a template vs restructure a renderable array in preprocess, and which audience should be doing that work?
Comment #2
joelpittetComment #3
star-szrAs a developer, I prefer #2 (the "for themers" one) overall.
A template with only
{{ table }}in it is nearly useless IMO. If that's what we get for the #type table option, I don't know what benefit there is from providing a template there at all.Comment #4
star-szrAnd thank you for doing this :)
Comment #5
webchickYep, agreed with Cottser. #2 is also closer to D7's theme function, which means less wrangling for the (uh, 1 ;)) site(s) out there who want to override this template.
I can understand the rationale for wanting code-reuse, and if we were talking about table.twig vs. views-table.twig or something like that, where both were going to be used throughout a site and it would be super annoying to have to make changes in both to keep them consistent, then this would be a tougher choice. But we're talking about a one-off template in a very specialized module that's basically only for user 1.
What might be nice though is a brief comment in the template above
'template' => 'update-version',explaining why we didn't just use #type => table here. And possibly also a normal, nice-to-have follow-up to bring this page generally more inline with other admin tables. For example, if those "download / release notes" were under an "operations" drop button we probably wouldn't need to do such special-casing here. But I don't want to hold a straight conversion issue up on a redesign.Comment #6
sunThat's what I've been saying a dozen of times already:
It's pretty much pointless to have a theme function/template for tables. A table is a table. There's hardly a use-case for overriding the markup of a table.
For the same reason, it doesn't make sense to repeat the entire markup for tables in individual templates. That only achieves the opposite: Inconsistency + duplicate code + unmaintainable templates.
The only sensible use-case is to replace the table altogether with markup that is not a table. That's what should lead the architecture and what we should optimize for.
— i.e., hand me the underlying (table) data in a way I can replace the (entire) table output with custom markup of my choice (in a particular place). But don't make me re-invent every single table from scratch.
Comment #7
joelpittet@sun have a gander at the preprocess function that generates the #type=>table.
If you were to use just
#type=>tableyou'd have to build markup in PHP for the cell contents, which I'm attempting to avoid at all costs:\ See #prefix/#suffix below:AND
Without the theme function for this
{{ table }}you'd have to either duplicate all that preprocess work in the controller/buildForm/etc which's create this specific#type=>tableor maybe hack a 'table--update-version.html.twig' together which would be likely gross. Or (this doesn't work from what I understand, yet) do that table preprocess suggestion with alatemplate_preprocess_table__update_version()function.I'd prefer the latter custom preprocess suggestion, if it worked and if that was the philosophy we'd all like to adhere to but the first point is still a big problem in my eyes (themer needs to extend that preprocess suggestion in their theme to change an HTML class of "version-date").
Comment #8
steveoliver commentedGiven all the points everyone has made so far, the "-themers" version makes the most sense to me:
1. It keeps markup out of preprocess
2. It keeps Twig template useful
3. It allows for changing the format--from table to _whatever_--easily, for a themer.
I would +1 RTBC this if a comment was added to the themers patch as webchick suggested in #5 ("a brief comment in the template above
'template' => 'update-version', explaining why we didn't just use #type => table here").Comment #9
l0keWaiting on #1898466: update.module - Convert theme_ functions to Twig to reroll patch.
Comment #10
l0keRerolled patch. Comment added.
Comment #11
joelpittetThanks @lokeoke here are a couple changes.
Need to add a newline to the end of the twig template.
Maybe this would be better written as...
from: allow to change format easily.
to: allow for easier template changes.
Thoughts?
Comment #12
l0keMay be "keep markup out of preprocess and easier template changes"?
Comment #13
joelpittetBetter but strange in context:
How about:
Comment #14
l0keUpdated patch.
Comment #15
steveoliver commentedLooks good. I agree that a solitary {{ table }} is pointless in a template, even this one.
My only comments before considering this RTBC:
Need newline back.
If we're not going to presume a table is in this template, maybe genericize the attributes description, like this?:
- attributes: HTML attributes suitable for a container element.
Comment #16
joelpittet@steveoliver item #15.1 is done the newline was fixed in #14. The interdiff will getcha like that, it tricked me for a second. too;)
#15.2 I'm good with that attributes description change too, maybe move it to the top of the list as well for consistency with other templates?
Comment #17
l0keThanks for review! Updated the patch.
Comment #18
steveoliver commentedThis one's cooked!
Comment #19
alexpottCommitted 4f5d858 and pushed to 8.x. Thanks!
Reflowed comment on commit to use the full 80 characters.
Comment #21
m1r1k commented