Problem/Motivation
While working on #3024682: Migrate UI - add human-friendly module names to the Review form, we noticed that the code was unclear, making it look as though the three items in each row of the table were more different than they are.
Note: for manual testing, set up a D6 or D7 database as a migration source. Then visit /upgrade and go through the form until you reach /upgrade/review.
Proposed resolution
The current code creates a <span> element inside one of the table cells, and adds CSS classes to that inner element.
Remove the <span> element. Instead, add the CSS classes to the table element. This simplifies both the render array and the resulting markup.
Remaining tasks
User interface changes
The markup on the review form (/upgrade/review) is simplified, but there are no visible changes.
API changes
None
Data model changes
None
Original report by @quietone
This is a followup to #3024682: Migrate UI - add human-friendly module names to the Review form. The patch in #105 over there contained out of scope changes which made it to RTBC but had to be removed. This is to preserve the improvement to the ReviewForm.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 3134300-18.patch | 5.03 KB | alexpott |
| #18 | 13-18-interdiff.txt | 2.28 KB | alexpott |
| #13 | 3134300-13.patch | 4.55 KB | quietone |
| #13 | interdiff-9-13.txt | 4.11 KB | quietone |
| #9 | 3134300-9.patch | 2.31 KB | quietone |
Comments
Comment #2
quietone commentedA patch with the improvements.
Comment #3
quietone commentedComment #4
quietone commentedNo longer postponed.
Comment #5
benjifisherThe patch fails to apply because the first line of context does not match the current comment:
We wanted to update that comment anyway. Maybe we can do it as part of this issue.
Comment #6
benjifisherComment #7
quietone commentedReroll
Comment #8
benjifisherThe patch in #7 looks good, but I would like one small change:
In the first render array, the patch leaves the key as
source_module, but in the second array the key is changed tosource_module_name. I would like to keep these consistent.Comment #9
quietone commentedYes, that is odd. All fixed now.
Comment #10
benjifisher@quietone, thanks for the update!
The patch in #9 looks good to me: RTBC.
The patch saves a few lines of code, which I like, but that is not the reason for this issue. Each row of the table consists of three render arrays. Before this patch, two of them are
'#type' => 'markup'(the default, thus omitted) with a single'#plain_text'key. The third is different:'#type' => 'html_tag'with three other keys. It takes thought to figure out that the output will be pretty similar to the other two entries, but with some CSS classes attached. I do not like to think that hard. ;)After the patch, it is much easier to see that the three render arrays are similar, except that one of them has some extra CSS classes.
OK, I do like to think that hard, but I want to save the effort for when it matters.
Comment #11
alexpottPotentially a better change then this would be to do something like
This way we have less html in this form and we're not dependent on arbitrary spans. All the cells are plain td elements with no html inside them. And it's easier to alter because the attributes are not part of an html string.
Not that making this change will require test changes since we do:
But this can be changed to
Comment #12
benjifisherWhere are these options documented?
According to https://api.drupal.org/api/drupal/elements/9.0.x,
so I expect to see
dataandwrapper_attributesin the API docs for the Table element. Instead, the only place I find them is in the API docs for the Twig template table.html.twig.Do we need a documentation issue to add something to Table.php? (I have not yet searched for an existing issue.)
Another mystery: what class handles
'#type' => 'markup'?Update: on second look, I see that there is a link from the Table api docs to the table.html.twig API docs.
Comment #13
quietone commentedFixes for #11.
Comment #14
quietone commented@benjifisher, Following the links in #12, I still can't find documentation for #wrapper_attributes. Where is it? Thx.
Comment #15
benjifisher@quietone:
I did not see your question until I wrote the comment below (including the "undocumented feature" part) and had to reload the page. I only found
#wrapper_attributesby searching the codebase. It is in the usage example of class Table. Looking again, I do not see it in the Twig template, despite what I said in #12.I like the idea in #11 (implemented in #13) of adding CSS classes to the existing HTML elements instead of creating a new
<span>. But this is a step backwards in terms of making the PHP easy to read. Also, I am beginning to think that the use of#wrapper_attributesis an undocumented feature.I would rather move the CSS classes to the
<tr>element, or maybe even the<table>element. Is there a semantic reason for attaching them to the<td>?Moving the CSS classes to the row would look something like this:
Going back to a multi-line array for the CSS classes makes the BEM structure clear, and moving the classes away from the
<td>elements makes that structure easier to understand.It is not hard to adjust the CSS selectors:
or
I think the second version would also work if we moved the CSS classes to the
<table>element.This will require updating the corresponding CSS in the
stableandstable9themes and in the tests.Comment #16
benjifisherThe next issue on my list is #3088215: Use styling from Upgrade Status module on Review form. Maybe we should abandon this issue and make the improvements as part of that one.
P.S. Or else postpone this issue on that one.
Comment #17
quietone commentedWow, what I thought would be a simple change has morphed into changing the themes.
I agree with the suggestion to postpone this on #3088215: Use styling from Upgrade Status module on Review form. And it looks like we should make an issue to for documenting #wrapper_attributes.
Comment #18
alexpottSpent sometime reading the table theme docs on template_preprocess_table().
It turns out we can do even simpler if we use #rows ... less stuff.
Comment #19
quietone commented@alexpott, thank you! I found the doc page you referred to and that is very straightforward.
I installed the patch and navigated to the Review form. There were no errors and the display was correct. I think this is RTBC. Changing back to NR to see if anyone agrees with me.
Comment #20
benjifisherI think it would be even simpler to move the CSS classes to the row, as I suggested in #15. But maybe we can consider that as part of #3088215: Use styling from Upgrade Status module on Review form. (I have decided that that issue still needs some work, not just tweaks, so I am less reluctant to require a reroll there.)
There is a trade-off: putting the CSS classes in one long line makes it easier to scan the code but harder to see the BEM structure of the classes.
I think the patch in #18 is an improvement over the current code. Let's get it in in the spirit of incremental improvement. RTBC.
Comment #21
benjifisherI am updating the issue summary, using the standard template.
Comment #23
catchNice clean-up.
Committed 940e609 and pushed to 9.1.x. Thanks!