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? |
---|---|---|---|
file | theme_file_widget_multiple | function | form table draggable |
Instructions to test manually
- Create a new content type with a File field that takes multiple values:
- Click "Menu" -> "Structure" -> "Content types"
- Click "Add content type"
- Put any value in "Name" and then click "Save and Manage fields"
- Under "Add new field": put anything in "Label" and set Field Type to "File" - and click "Save"
- Change "Allowed number of values" to "Unlimited" and click "Save field settings"
- Click "Save settings"
- Click "Shortcuts"
- Click "Add content"
- Click on the content type you created
- Under the field you created, upload a couple files
Related issues
Comment | File | Size | Author |
---|---|---|---|
#19 | interdiff.txt | 4.75 KB | joelpittet |
#19 | 1938902-19-type-table-file.patch | 4.59 KB | joelpittet |
#15 | file-widget-multiple-table-1938902-15.patch | 848 bytes | dsnopek |
#12 | file-widget-multiple-table-1938902-12.patch | 722 bytes | dsnopek |
#11 | Selection_004.png | 9.08 KB | dsnopek |
Comments
Comment #1
duellj CreditAttribution: duellj commentedComment #2
duellj CreditAttribution: duellj commentedOuch, it is clear that I don't have the brain power to do this now. It's a tricky one.
Comment #3
jibranAnyone up for this in portland.
Comment #4
phenaproximaI'll give it a shot. Here's hoping I can wrap my brain around it!
Comment #5
phenaproximaI regret to say I need to punt on this for now due to a prior engagement...you're right, duellj, this is damned tricky. I'll try to get back to this if I can, but if anyone else wants to take this on, please feel free!
Comment #6
pplantinga CreditAttribution: pplantinga commentedThe function really needs to be refactored, but that's for another issue. Here is a straightforward patch.
Comment #7
pplantinga CreditAttribution: pplantinga commentedAaaannddd... whitespace errors *facepalm*
Here's an updated patch.
Comment #8
jibran#7: file-widget-multiple-table-1938902-7.patch queued for re-testing.
Comment #10
pplantinga CreditAttribution: pplantinga commentedRe-roll
Comment #10.0
pplantinga CreditAttribution: pplantinga commentedRemoving theme_file_formatter_table() since not a form element
Comment #11
dsnopekI added instructions to do manual testing and did some!
It looks fine when there are some items in the table. However, it doesn't match the previous behavior when there are no items! See the screenshots below.
Before the patch
When empty:
With two files uploaded:
After the patch
When empty:
With two files uploaded:
Comment #12
dsnopekAttached is a new version of the patch which some of the changes reverted, which fixes the bug I pointed out in #11. Please let me know what you think!
Comment #13
dsnopekActually, I started thinking about this and I think this patch is going in the wrong direction. It's replacing the code in
theme_file_widget_multiple()
, but what it probably should be doing is REMOVING that theme function all together and put the '#type' => 'table' element directly into the form!Comment #15
dsnopekOops! Well, here is the real patch that should have been for #12. :-) However, the next one I make will take the different approach I described in #13.
Comment #17
dsnopek#15: file-widget-multiple-table-1938902-15.patch queued for re-testing.
Comment #18
Snipon CreditAttribution: Snipon commented#15: file-widget-multiple-table-1938902-15.patch queued for re-testing.
Comment #19
joelpittetThis is likely not going to pass all tests but this is closer to what the conversion should look like.
If you just run the existing code through #rows attribute none of #type=> tables magic happens. Which includes doing the row sorting for you.
Also #empty still shows the header and the way it's used doesn't achieve the style you are looking for without the headers.
Hope that helps, and for the failures and exceptions maybe you can look into why those may be.
I've tested this manually but the tests either need to change or maybe #parents need to be put on some of the elements. @see https://drupal.org/node/1876710 for reference to what I did here. Also, if you don't understand let me know and I'll comment lines for clarity.
FYI, type=>table is not my favourite thing to build... it's a lot of work for little gain. Hopefully the removed loops will help a bit with performance testing.
Comment #21
joelpittet#19: 1938902-19-type-table-file.patch queued for re-testing.
Comment #22.0
(not verified) CreditAttribution: commentedAdded instructions for manual testing.
Comment #23
joelpittet19: 1938902-19-type-table-file.patch queued for re-testing.
Comment #26
sidharthapUpdating issue tag. Will have a look at Drupal Camp Mumbai sprint on this weekend
Comment #27
mitsuroseba CreditAttribution: mitsuroseba commentedComment #28
mitsuroseba CreditAttribution: mitsuroseba commentedSeems like we already use '#type' => 'table', so what we need to do ?
file.field.inc:131
Comment #29
akalata CreditAttribution: akalata commentedClosing as dupe of #1898070: file.module - Convert theme_ functions to Twig, since that's where this task was completed.