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',
      ),
    );

    ...
  }

#1876718: Allow modules to inject columns into tables more easily
#1876712: [meta] Convert all tables in core to new #type 'table'

CommentFileSizeAuthor
#6 1948374-6-table-type-attributes.patch866 bytesduellj
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

larowlan’s picture

+1 for colspan

nick_schuch’s picture

+1 for colspan

tim.plunkett’s picture

Priority: Major » Normal

The issue summary doesn't make this clear why it is major.

sun’s picture

I believe I added #wrapper_attributes for this and it should be in HEAD already.

joelpittet’s picture

@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:)

duellj’s picture

Title: #type 'table' allow classes on table cells » #type 'table' allow attributes on table cells
Status: Active » Needs review
FileSize
866 bytes

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

andypost’s picture

sun’s picture

Status: Needs review » Reviewed & tested by the community

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

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 23c27a8 and pushed to 8.x. Thanks!

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

removed the change order from related issues