Problem/Motivation
Due to the structure of the row's columns (tds) in the new #type=>table being the built as the elements within them. It is currently not possible to add #attributes to the table data.
Proposed resolution
Allow more of the theme wrapper's #theme=>table
functionality access to the #type=>table
. Possible to allow rows to be built with #rows as #theme=>table uses and grab the cell data from that in the form_process_table
and other callbacks
API changes
Snippet from: http://drupal.org/node/1876710
// Building Rows with #type=>table (currently)
foreach ($entities as $id => $entity) {
...
// Some table columns containing raw markup.
$form['mytable'][$id]['label'] = array(
'#markup' => check_plain($entity->label()),
);
$form['mytable'][$id]['id'] = array(
'#markup' => check_plain($entity->id()),
);
...
}
// Building Rows with #type=>table (currently)
foreach ($entities as $id => $entity) {
...
// Some table columns containing raw markup.
// Leave as is.
$form['mytable'][$id]['label'] = array(
'#markup' => check_plain($entity->label()),
);
// Allow cell data form #theme=>table
$form['mytable'][$id]['id'] = array(
'data' => check_plain($entity->id()),
'#attributes' => array(
'class' => array('table-id-class'),
'data-html5-key' => 'value',
),
);
...
}
Related Issues
#1876718: Allow modules to inject columns into tables more easily
#1876712: [meta] Convert all tables in core to new #type 'table'
Comment | File | Size | Author |
---|---|---|---|
#6 | 1948374-6-table-type-attributes.patch | 866 bytes | duellj |
Comments
Comment #1
larowlan+1 for colspan
Comment #2
nick_schuch CreditAttribution: nick_schuch commented+1 for colspan
Comment #3
tim.plunkettThe issue summary doesn't make this clear why it is major.
Comment #4
sunI believe I added #wrapper_attributes for this and it should be in HEAD already.
Comment #5
joelpittet@sun does there need to be two ways to do the same thing? Couldn't the form api handlers just expect the same format of rows that get put through #theme=>table?
It seems a bit strange to me that #type=>table is themed by #theme=>table but doesn't expect to get the same structure going into it. Maybe there is a good reason for this... or very possibly I am doing something horribly wrong:)
Comment #6
duellj CreditAttribution: duellj commented@sun: wrapper_attributes don't get applied to table cells for table #type form elements (see drupal_pre_render_table()), which makes it impossible to add classes or colspans on table cells. If we do want to continue to use the #wrapper_attribute syntax for this, I've created a patch that allows table cell attributes.
Comment #7
andypostThe issue should unfreeze #1855402: Add generic weighting (tabledrag) support for config entities (DraggableListController) which holds 3 issues
Comment #8
sunThe patch in #6 looks very good and valid to me.
There are no tests for #type 'table' at all yet, and this issue would not be the right place to start adding them, so marking RTBC.
Comment #9
alexpottCommitted 23c27a8 and pushed to 8.x. Thanks!
Comment #10.0
(not verified) CreditAttribution: commentedremoved the change order from related issues