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.
Issue #2151109 by joelpittet, c4rl, IshaDakota, pplantinga, gnuget, longwave, jeanfei, sbudker1: Convert theme_system_modules_details() to Twig
Task
Convert theme_system_modules_details() to a Twig template.
Remaining tasks
PatchPatch review- Manual testing
Profilingnot needed - admin-only change (per #25)
Steps to test
Visit the http://d8.dev/admin/modules/
page and review markup and check for visual regressions.
Comment | File | Size | Author |
---|---|---|---|
#77 | convert-2151109-77.patch | 13.53 KB | joelpittet |
#77 | interdiff.txt | 1.3 KB | joelpittet |
#71 | convert-2151109-70.patch | 13.57 KB | joelpittet |
#71 | interdiff.txt | 2.03 KB | joelpittet |
#66 | interdiff.txt | 6.83 KB | joelpittet |
Comments
Comment #1
star-szrAdding a commit message to the issue summary so the folks who already worked on #1987410: [meta] system.module - Convert theme_ functions to Twig and #1898454: system.module - Convert PHPTemplate templates to Twig (comment #41 and above aka @c4rl) get credit.
Comment #2
star-szrComment #3
gnugetI'm going to work on this, this night
Comment #4
mfernea CreditAttribution: mfernea commentedShouldn't the task be to remove theme_system_modules_details and construct the render array differently in ModulesListForm->buildForm() as per #1938930: Convert theme_system_modules_details() to #type table?
Comment #5
star-szrComment #6
joelpittet@mfernea I'd prefer we didn't have to do this conversion but the type=>table conversion is stuck right now, so need some eyeballs over there. Maybe you could find where I went wrong with the patch in #29?
Comment #7
mfernea CreditAttribution: mfernea commented@joelpittet: I wish I had the required knowledge :), but I don't. I'm still in the learning phase in this matter.
Comment #8
joelpittet@mfernea no worries at all, there is sooo much things still that could use your eyeballs in the #1757550: [Meta] Convert core theme functions to Twig templates! And also I still find type=>table difficult to comprehend and I've done quite a few. They can be tricky, especially when they are form based and the keys need to change for the submit handler to accept the values.
Comment #9
mfernea CreditAttribution: mfernea commented@joelpittet: Ok, I'll search there for things that I can tackle. :)
Comment #10
star-szrPostponed on the #type table conversion in #1938930: Convert theme_system_modules_details() to #type table then.
Comment #11
star-szrI closed #1987410: [meta] system.module - Convert theme_ functions to Twig so I'm just going to make this a child of #1757550: [Meta] Convert core theme functions to Twig templates but it will likely/hopefully end up as a duplicate of the #type table issue.
Comment #12
akalata CreditAttribution: akalata commentedComment #13
akalata CreditAttribution: akalata commentedComment #14
akalata CreditAttribution: akalata commentedComment #15
star-szrI have a review I will post later or tomorrow. Overall looks great :) thanks @akalata!
Comment #16
star-szrThanks again @akalata!
I think the Twig template has two blank lines at the bottom which git is complaining about:
Just in general I'm wondering if more of the markup in preprocess could be moved to the Twig template but there might be reasons why not, we can talk about it at DrupalCon :)
Minor: I think we usually pluralize these, like…
Prepares variables for module detail templates.
Internal pluralization may not be quite right but hopefully you get the idea.
Minor: Add dots.
Not sure if it's possible but would be nice to avoid calling drupal_render() if we can.
Minor: Add a dot to the end.
Nice find! Minor: We can also add a trailing comma here.
Minor: Extra space after double arrow/hash rocket/fat comma (
=> $renderer
).I think the second sentence should be on its own line, with a blank line in between per https://www.drupal.org/node/1354#general.
The modules one is well formatted, the end of the header needs to end in a colon to set up the next list per https://www.drupal.org/node/1354#lists.
Add dots.
Nice :)
Potentially the
set
could be all on one line here.Comment #17
akalata CreditAttribution: akalata commentedMuchas gracias for the review @Cottser!
Updated patch addresses feedback in #16 and renames to system_module_details for less pluralization confusion.
Specific to #3, I'm not sure which is better: calling
\Drupal::service('renderer')->render($stuff)
multiple times, or declaring$renderer = \Drupal::service('renderer');
and calling$renderer->render($stuff)
multiple times. The second pattern of usage was already present in the patch, but the first usage seems clearer to me?Re: Removing markup from the preprocess -- most of that markup is provided via a
'#type' => 'details',
, I'm not sure if there's an easy way to call that formatter from within a twig template? The only other markup is the<label>
element, and it's important to get that right for accessibility.Comment #18
star-szrTechnically changing to system_module_details would be a BC break so not sure if that would be allowed in this stage of the release.
For point 3 I was thinking of removing the drupal_render() altogether and just render it in the Twig template but I did not look at it super closely.
Thanks!
Comment #19
akalata CreditAttribution: akalata commentedOk, so no BC break. I'd forgotten about the "just render it in the template" piece as well - seems to work ok on my end.
Comment #20
joelpittetIs description supposed to be 2 instead of index 1?
Maybe this could be done somehow in a loop to avoid this kind of thing?
This is a nice catch and also this would be nice in the template.
Same here.
This would be awesome in the template.
Comment #21
lauriiiLets put enable after name because those two are always the only ones existing
"A list of administration links provided by the module"
Missing newline
Comment #22
akalata CreditAttribution: akalata commented#20.1 - yes, good catch. We could put it in a loop, but that makes it less semantic when the variables are passed to the template.
#20.2, 20.3, 20.4: I've moved these into the template, though I'm not sure that this is the correct solution because now it's building the
<details>
element manually, instead of using'#type' => 'details'
.#21 feedback also addressed - thanks @lauriii!
Comment #23
lauriiiComment #24
joelpittetGot rid of all the early rendering, the new line on required by/requires was added by the new inline item_list type and has another issue to get in to fix that but this totally side steps that problem by building the inline comma list in twig.
I'm sure we can still clean this up some more, thank you very much @akalata for taking this on it's looking awesome.
Hope I didn't break it more but seems to work locally.
Comment #25
lauriiiAdmin facing pages don't need profiling.
I did the manual testing:
Before:
After:
The visual changes are approved because its broken in the head. It is being fixed also in here: #2557367: Fix inline list CSS
Comment #26
akalata CreditAttribution: akalata commentedShould we close #1938930: Convert theme_system_modules_details() to #type table in favor of this patch, and approach theme_system_modules_uninstall() in the same way?
Comment #27
akalata CreditAttribution: akalata commentedI've removed the code in theme_system_modules_uninstall() that #24 added, and fixed the docs for template_preprocess_system_modules_details() (
#requires
and#required_by
are provided starting with#
).Comment #28
akalata CreditAttribution: akalata commentedComment #29
lauriiiAt least these three are actually required. There is also #attributes variable
Comment #30
stefan.r CreditAttribution: stefan.r commentedGetting rid of theme functions should be major, right?
Comment #31
stefan.r CreditAttribution: stefan.r commentedComment #32
derheap CreditAttribution: derheap as a volunteer commentedI have made some screenshots. With the patch applied Chrome produces an extra space before the module description.
That should be removed, like in the code below.
<summary aria-controls="{{ module.id }}" role="button"><span class="text module-description">{{ module.description }}</span></summary>
HEAD:
With the patch:
Comment #33
akalata CreditAttribution: akalata commented@lauriii re: #29, How do we define "required" in this sense? I couldn't find anything on it in the docs. I considered those 3 items optional because not every module will have those values to pass to the template. The missing
#attributes
is a good catch.@derheap: Thanks for the screenshots! I enjoyed helping you at the Barcelona sprint.
Comment #34
akalata CreditAttribution: akalata commentedThis patch adds #attributes to the docblock for template_preprocess_system_modules_details() and fixes the extra space in Chrome identified in #32.
Comment #35
lauriiiThey are required in that sense that it will cause warning if the variable doesn't exist :)
Comment #36
akalata CreditAttribution: akalata commentedAhh, I see. joel's changes had introduced that. :)
Comment #37
joelpittetBack to RTBC as concerns after #25 has been addressed.
Comment #38
lauriiiLinks are still required.
TBH we shouldn't be making this kind of assumptions..
Comment #39
akalata CreditAttribution: akalata commented@lauriii: Should we just not worry then about flagging things as "optional" since we're getting them from the
$form
anyway? Even if there's no content, they're at least empty and exist.Comment #40
derheap CreditAttribution: derheap as a volunteer commentedI reviewed the patch and the interdiff.
It addresses #29, #38 and the extra space from #32.
@aklata & @ laurii: The template checks for requires, links etc. So no need to worry about.
So I am putting this back to RTBC
@akalata:
I enjoyed your help and support at the sprint. It very helpfull to hear, that reviews and screenshots are as important as patches.
Comment #41
joelpittetRTBC++ thanks @derheap for doing final checks, the thorough review from @lauriii and the patches @akalata
Comment #42
catchThis conflicts with #2372183: Display same info for themes as for modules could use cross review.
Comment #43
LewisNymanI would commit this one first. It shouldn't be too hard to convert the class changes in #2372183: Display same info for themes as for modules in the new twig template.
Comment #44
jcnventura CreditAttribution: jcnventura at Wunder commentedI'm also postponing #2574721: Provide access to action links in the modules page on small screens on this one. Not sure if the blocker tag is still used for anything useful.
Comment #45
star-szrThis is looking very good, just found two minor documentation points that can either be fixed on commit or in a normal follow-up. Awesome work @akalata, @lauriii, @joelpittet and all!
Minor: Ensure that the Testing module's machine name is printed. Add "the", apostrophe for module. Needs to be re-wrapped to 80 chars also because those changes would put it over.
Minor: s/namet/name/
Minor: In docs we usually use uppercase ID I think.
Comment #46
akalata CreditAttribution: akalata commentedRe 45.3, I couldn't find anything specific in the docs, but a quick search of the codebase shows "unique id", "unique ID", and "unique identifier" are all used. I think "unique identifier" is clearest in this case, because these are not numeric or UUIDs.
Attaching a patch with doc changes to make it easier for a committer. :)
Comment #47
star-szrThanks @akalata :)
Oops there is one more here, s/unqiue/unique/.
PS. Of course in my previous comment I meant three, not two :)
Comment #48
jcnventura CreditAttribution: jcnventura at Wunder commentedSaving @akalata some time. Because Barkalona. And swimming.
And besides, this is blocking me on two other issues.
PS: priorities not in the order listed.
Comment #49
star-szrI don't want to hold this up but have to ask: are we okay with these translatable strings losing some context? We could probably use trans tags (and maybe set tags if needed?) to keep the translatable strings the same.
Comment #50
jcnventura CreditAttribution: jcnventura at Wunder commentedAs a translator myself, yes we shouldn't touch those strings at this point. Problem is, I can't seem to make it work except for the first one (machine name).
In the case of the version, when keeping the translatable string, the version number simply refuses to show up.
In the case of the required_by, HTML gets escaped, and I can see the tags.. Same is applicable to requires, but not so easy to spot.
Is there anyway to have HTML survive a filter like t({'@var': var|safe_join(', ')}) without getting escaped?
Comment #51
star-szrComment #52
star-szrThanks @jcnventura! This should fix the version and the requires/required by needs some more thought. Some or all of this may need to use trans tags instead.
Comment #54
jcnventura CreditAttribution: jcnventura at Wunder commentedNice one, that
render
filter.. I guess someone should update https://www.drupal.org/node/2357633, with that and other missing filters?Comment #55
star-szrI'm not super thrilled about this but it works and maintains the translatable strings. The alternative seems to be a lot of looping and
if
s in the template which seems even uglier. Thoughts?Comment #56
star-szr@jcnventura that would be great, the changed/added filters and functions are in the \Drupal\Core\Template\TwigExtension class, getFunctions and getFilters methods.
Comment #57
star-szrAfter some more digging and IRC discussion with @xjm and @alexpott I created #2579091: Make safe_join Twig filter return a Markup object. This can still go in and be refactored later IMO.
Comment #59
star-szrLike so.
Comment #60
joelpittetI'd prefer to not do the renderer stuff, but that can be likely added to #2579091: Make safe_join Twig filter return a Markup object
There is no visual regression to speak of:
Before:
After:
But there is markup regression that likely needs to be addressed.
Comment #61
joelpittetSorry had my diff backwards in #60
But here is a couple more markup regressions.
Comment #62
star-szrThanks @joelpittet there is also an empty links div, hopefully this isn't too big of a change.
There's still some more but this is all I have time for now.
Comment #63
star-szrOkay room for one more.
Comment #64
star-szrLalala. Some of this is kinda ugly but not sure how else to do it.
Comment #65
star-szrSorry for all the patches, missed one thing. This should be pretty darn close.
Comment #66
joelpittetRemove the unnessasary build up of the header text by moving it to the template and avoiding the hardcoded indexes since the classes are already there I removed the #header key all together and duplicate class build-up that isn't used. Avoids dealing with ['data'] and ['class'] keys that are for #theme table.
Get the
|render
out of the template as it would be nice if it weren't necessary to treat those variables as render arrays in the first place... If we can avoid treating variables as render arrays, the better (exception for maybe checking if they are empty).Comment #67
star-szrOverall looks like a good direction, thanks @joelpittet! A couple points:
I don't think we can add this span stuff to the translatable string.
Not totally sold on this part being display logic but I could probably be convinced.
Comment #69
joelpittetRe #67.1 I'd rather just remove the span all together, why do we need that class wrapping it and the ltr looks like a mistake. Needs git bisect to find out what is up there...
#67.2 Without that in the template any other link type will be overwritten and you'd have to get pretty creative in preprocess to get other links(if needed). This just exposes this hardcoded "which links to display" decision that to the themer.
Comment #70
star-szr#67.1 is for the module filter so it needs to stay.
Fair enough on point 2 I suppose, but doesn't that also mean that if modules want to add more links they're stuck? I guess the only reason why we iterate specifically through those 3 is to show them in that order?
Comment #71
joelpittetFixed my bad copy/paste and semi-reverted #67.1 because apparently JS tied to that span tag and I'd rather just remove it all together... JS should be a data-attribute to prevent unnessary dom traversal but that is out of scope here.
Comment #72
joelpittetRe #70
If modules want to add more links they coudn't before either. So I'm not changing this, I'm just moving it it's responsibility away from preprocess. Yeah not sure about it being an order thing but that seems to be a good guess for why... there are likely better ways to do that but out of scope here I think.
Comment #74
joelpittetWhoops, needs review.
Comment #77
joelpittetI guess I should wake up, seriously. I'm not drinking, promise! ... maybe I should start.
Comment #78
RainbowArrayFrom what I can tell, looks like all remaining feedback has been addressed. Back to RTBC.
Comment #79
webchickYay, another one bites the dust-ah!
Committed and pushed to 8.0.x. Thanks!