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

  1. Create a new content type with a File field that takes multiple values:
    1. Click "Menu" -> "Structure" -> "Content types"
    2. Click "Add content type"
    3. Put any value in "Name" and then click "Save and Manage fields"
    4. Under "Add new field": put anything in "Label" and set Field Type to "File" - and click "Save"
    5. Change "Allowed number of values" to "Unlimited" and click "Save field settings"
    6. Click "Save settings"
  2. Click "Shortcuts"
  3. Click "Add content"
  4. Click on the content type you created
  5. Under the field you created, upload a couple files

Related issues

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

duellj’s picture

Assigned: Unassigned » duellj
duellj’s picture

Assigned: duellj » Unassigned

Ouch, it is clear that I don't have the brain power to do this now. It's a tricky one.

jibran’s picture

Anyone up for this in portland.

phenaproxima’s picture

Assigned: Unassigned » phenaproxima

I'll give it a shot. Here's hoping I can wrap my brain around it!

phenaproxima’s picture

Assigned: phenaproxima » Unassigned

I 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!

pplantinga’s picture

Status: Active » Needs review
FileSize
1.04 KB

The function really needs to be refactored, but that's for another issue. Here is a straightforward patch.

pplantinga’s picture

Aaaannddd... whitespace errors *facepalm*

Here's an updated patch.

jibran’s picture

Status: Needs review » Needs work

The last submitted patch, file-widget-multiple-table-1938902-7.patch, failed testing.

pplantinga’s picture

Status: Needs work » Needs review
FileSize
864 bytes

Re-roll

pplantinga’s picture

Issue summary: View changes

Removing theme_file_formatter_table() since not a form element

dsnopek’s picture

Status: Needs review » Needs work
FileSize
19.01 KB
16.31 KB
19.12 KB
9.08 KB

I 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:

Selection_004.png

With two files uploaded:

Selection_002.png

After the patch

When empty:

Selection_005.png

With two files uploaded:

Selection_003.png

dsnopek’s picture

Status: Needs work » Needs review
FileSize
722 bytes

Attached 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!

dsnopek’s picture

Actually, 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!

Status: Needs review » Needs work

The last submitted patch, file-widget-multiple-table-1938902-12.patch, failed testing.

dsnopek’s picture

Status: Needs work » Needs review
FileSize
848 bytes

Oops! 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.

Status: Needs review » Needs work

The last submitted patch, file-widget-multiple-table-1938902-15.patch, failed testing.

dsnopek’s picture

Status: Needs work » Needs review
Snipon’s picture

joelpittet’s picture

This 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.

Status: Needs review » Needs work

The last submitted patch, 1938902-19-type-table-file.patch, failed testing.

joelpittet’s picture

Status: Needs work » Needs review

#19: 1938902-19-type-table-file.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 1938902-19-type-table-file.patch, failed testing.

Anonymous’s picture

Issue summary: View changes

Added instructions for manual testing.

joelpittet’s picture

The last submitted patch, 19: 1938902-19-type-table-file.patch, failed testing.

The last submitted patch, 19: 1938902-19-type-table-file.patch, failed testing.

sidharthap’s picture

Issue summary: View changes
Issue tags: +drupalcampmumbai sprint

Updating issue tag. Will have a look at Drupal Camp Mumbai sprint on this weekend

mitsuroseba’s picture

Assigned: Unassigned » mitsuroseba
mitsuroseba’s picture

Assigned: mitsuroseba » Unassigned

Seems like we already use '#type' => 'table', so what we need to do ?
file.field.inc:131

  $variables['table'] = array(
    '#type' => 'table',
    '#header' => $headers,
    '#rows' => $rows,
    '#attributes' => array(
      'id' => $table_id,
    ),
    '#tabledrag' => array(
      array(
        'action' => 'order',
        'relationship' => 'sibling',
        'group' => $weight_class,
      ),
    ),
  );
akalata’s picture

Status: Needs work » Closed (duplicate)

Closing as dupe of #1898070: file.module - Convert theme_ functions to Twig, since that's where this task was completed.