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.
Task
Convert the following theme functions to use the new table #type:
Module | Theme function name | Where in Code | What is it really? |
---|---|---|---|
field_ui | theme_field_ui_table | function (unusable) | table |
Steps to Reproduce
- Visit admin/structure/types/manage/article/form-display
- Test form saves.
- Compare markup.
Related issues
Comment | File | Size | Author |
---|---|---|---|
#56 | convert-1938900-55.patch | 19.8 KB | joelpittet |
#56 | interdiff.txt | 5.05 KB | joelpittet |
#50 | interdiff.txt | 7.52 KB | lauriii |
#50 | convert_field_ui_theme-1938900-50.patch | 19.19 KB | lauriii |
#48 | convert_field_ui_theme-1938900-48.patch | 19.01 KB | joelpittet |
Comments
Comment #1
swentel CreditAttribution: swentel commentedtagging
Comment #2
star-szrSince this isn't a 'form' table, I think it will just need a Twig conversion for now. Tentatively postponing this one and activating #1898068: field_ui.module - Convert theme_ functions to Twig.
If I'm wrong, please correct me :)
Comment #3
star-szrShould have confirmed with @duellj first, but he said this would actually work better as #type table. Sorry for the mix-up.
Comment #4
duellj CreditAttribution: duellj commentedUnfortunately, this table conversions requires colspans, which aren't yet supported by #type table. This issue needs to make it in first: #1948374: #type 'table' allow attributes on table cells
Comment #5
swentel CreditAttribution: swentel commentedThat issue is in, let's go :)
Comment #6
neochief CreditAttribution: neochief commentedComment #7
jibranTagging.
Comment #8
neochief CreditAttribution: neochief commentedNow, after reviewing the field_ui code I'm not even sure that this task should be done at all.
theme_field_ui_table() is used for field_ui_table element rendering. I don't see a reason to translate one element into another, since in the end of the day, they both use theme_table().
I also was thinking about removing field_ui_table element at all in favor of table element, but it's used in several places, so it's not a really good idea.
There might be some other approach, but I'm not sure I understand what you guys had in mind during your conversations before. So, brief recap would be welcomed.
Comment #9
swentel CreditAttribution: swentel commentedYeah, field ui is also kind of special doing funky stuff. Also there's an issue to rethink Field UI a little over at #1963340: Change field UI so that adding a field is a separate task, so maybe we should defer to that issue and close this one ?
Comment #10
neochief CreditAttribution: neochief commentedYes, I think so. Please, reopen the issue if you think otherwise.
Comment #11
neochief CreditAttribution: neochief commentedComment #12
swentel CreditAttribution: swentel commentedRemoving tags for now.
Comment #13
tstoecklerThat one was fixed but the horror that is
theme_field_ui_table()
still exists.Comment #14
joelpittetThis probably hella wrong but on the right track... I think... Let's see how much tests this has:)
Comment #15
joelpittetI expect this will preRender in the top to bottom order.
This prerender method probably needs some thourough vetting, I mostly dumped it in and changed the array syntax.
Comment #17
joelpittetOk, well doesn't look too bad, probably need to just find an example someplace. Then just step through this with the debugger and modify till it works.
Comment #18
lokapujya1. Should this be a FormElement? since Table is a FormElement.
2. Had to do some scary things to get the table to render. See interdiff.
Comment #19
tstoecklerHmm... IMO it doesn't make much sense to add
FieldUiTable
as a dedicated element. Now that we have'#type' => 'table'
we should be able to set things like the colspan etc. that the pre-render function is currently doing directly in the form array when putting it together.Comment #20
joelpittet@lokapujya it is an extended Table element, since Table is a FormElement, it should be fine that we also extend Table.
This is the difference between the definition of a table and this type of table.
Unfortunately the union will clobber the existing '#pre_render' key and the Table::preRenderTable static method will not be called.
I'd hope these changes don't need to be made?
Comment #21
joelpittetSorry that should be more clear... we are making a
#type => table
in the theme function.Type=>table
is\Drupal\Core\Render\Element\Table
That is why it should be golden.
Comment #22
joelpittet@lokapujya what page are you using to see this?
Comment #24
lokapujyaadmin/structure/types/manage/article/form-display
@tstoeckler -
Great, that will make this help clean this up.
[$parent_class, 'preRenderTable'],
Removed that because the rows were getting duplicated.
It is because $this isn't available in a static function.
Well, I need a break from coding this issue. Spent too much time messing with preRender.
Comment #25
lokapujyaReverted that change; It was irrelevant to getting the table to render.
Comment #26
joelpittetOh they are being duplicated because I dumped the theme function logic for building the rows almost verbatim into the new prerender function. Sorry, my fault on that. I just tried to kick start this issue(didn't test).
There is only one instance of this type/theme function being used in core. I agree with @tstoeckler, we should just kill it off and move the necessary logic if possible to that.
Kind which I knew if contrib was using this at all... (Thinking about Greggles' Gotta Download Them All module to save the day, if I knew it was up to date to some degree)
Comment #27
lokapujyaRan one of the tests locally. The scary change pointed out in #20.3 causes a bunch of exceptions, and might be why the tests didn't run.
Comment #28
joelpittetOk no interdiff cus this is a different direction.
@tstoeckler this direction along the lines of what you suggested?
Comment #32
andypostIntentional removal of
drupal_render($child)
looks breaks forms embedded in this tableThis looks strange
somehow render of cell lost
Comment #33
joelpittetIn what way does it break them? I tested this and the form "seemed" to be working fine.
Re: #32.1 Yes, yes it does... need to find out how or why the rows are already converted for
#theme => table
on the$element
.Re: #32.1 I have a theory here... maybe those value keys need to be printed and that whole don't render #type => value, is because they were probably already rendered before they hit the theme function before or maybe they just need to be rendered outside the table.
Comment #34
joelpittetWhoops still needs work/new patch. Thanks for the review @andypost
Comment #35
lokapujyaPull Request. Remove mention of field_ui_element_info.
Comment #36
lokapujyaWhat's different about the field created in the failing test, in that it doesn't show up in the /form-display table? edit: If you get the /display page, field_test does show up.
edit: in other words, why is field_test created via fieldUIAddNewField() one of the "already built" elements? but, a new field added via the UI does show up in the table.
Comment #37
andypost@lokapujya probably because some properties are not configured for field.
PS: patch still applies with ofset
Comment #40
joelpittetI may have got the prerenders in the wrong order and there is duplicates now but the tests may pass...
It was missing some of the table preprocessing which made the extra fields missing for example 'links' and the responsive classes were missing.
Comment #43
star-szrRemoving the original table render seems to get things closer to me (the responsive stuff is probably not relevant in this case either) but field_tags is missing (probably similar to what you were mentioning with links @joelpittet), weird things are happening. This is a tricky one. Just seeing what the bot thinks about this one.
What I was seeing was the $elements array seems to get messed up in the loop and field_tags gets replaced with the data values from the body field or something equally odd.
Comment #44
star-szrMissing interdiff.
Comment #47
star-szrMaybe we need to keep the table pre_render but switch up what we do in the specific pre render to be even moreso like moving things around. Haven't yet studied in detail what is happening in each step.
Comment #48
joelpittetNow for something completely different...
Comment #49
lauriiiGreat to see the overall work. Amazing work @joelpittet!!
\o/
This probably shouldn't be there anymore
Missing return comment
Do we actually need the drupal_render there?
We can also say array($this, 'reduceOrder')
Is missing param docs
use $this instead
s/field/Field
Comment #50
lauriiiFixed the nits I found on my own review
Comment #51
star-szrJust for the record I did a markup diff, looks great! Will try to find some time to review the patch soon.
Comment #52
star-szrJust wondering if we should re-title this one along the lines of the language table one. Much more complex but overall feels like we're doing something similar.
Comment #53
lauriiiComment #54
star-szrOverall looks very good, some docs things and some thoughts on preserving BC below:
We need to update the docblock here now that it's a preprocess function.
https://www.drupal.org/node/1354#themepreprocess
For the least disruption I think we should consider that these methods on EntityDisplayFormBase (reduceOrder and tablePreRender) should be deprecated and wrap the FieldUiTable methods. We may not necessarily consider them API but they are public methods and not marked @internal so we should be mindful of that.
Continuing along that same line of thought, we would have two pre-renders in FieldUiTable, one to do the same as the previous pre-render, and one to do the similar things the theme function was doing before.
I think that or something along those lines is probably the right thing to do to preserve BC at this point.
The comment here should be updated because it doesn't live inside that class any more.
Minor: two spaces after the semicolon, should just be one.
The wording towards the end of this sentence gets a bit vague, what does "value of initial" mean? "holds the initial value"?
Should we consider pointing to template_preprocess_field_ui_table() instead here, in case that ever gets changed? Just a thought, feel free to say no.
Observation: Cool :)
Comment #55
xjmSimilarly to #1938912: Convert language content setting table theme to a twig template and as a child of #2348381: [META-0 theme functions left] Convert/refactor core theme functions, this is a good rc target!
Comment #56
joelpittetTried to address #54
Comment #57
star-szrI looked at this thoroughly and manually tested again, only two minor docs points. Otherwise RTBC, thanks all!
Super duper duper minor, can be fixed on commit: s/prerender/prerenders/.
Minor: Maybe we could copy over the param docs? preRenderRegionRows is missing docs here.
Comment #59
webchickDIE LAST THEME FUNCTION DIE!!
Committed and pushed to 8.0.x. YEAH! :D
Comment #61
swentel CreditAttribution: swentel commentedFollow up on #2605518: Table drag indentation is not rendered