This is a small patch to make the already very powerful theme system even more accessible and functional.

theme_table: This patch will allow you to tag cells as headers to make the already available functionally of _theme_table_cell accessible to you. By adding a header key with either one of the values 1, true, or `th` theme_table can now generate headings for you on the side of the table in a row in the centre anywhere you want them.

This is already implemented but duplicated in the latest patch for the modules administration page which makes the modules screen look so much neater with all the packages in one table and all the rows lined up. Each package heading can be table headings and even without style sheets are already styled appropriately.

ex:

    $cells[] = array('data' => 'Cell 1', 'header' => 1);
    $cells[] = array('data' => 'Cell 2', 'header' => true);
    $cells[] = array('data' => 'Cell 3', 'header' => 'th');
    
    $rows[] = array(
        'data' =>    $cells,
        'style' => 'font-weight : bold;'
    );
    return theme('table',array(),$rows);    

theme_links: As a newcomer I found using this function very frustrating due to its complexity and lack of documentation which is a pity because this is a very powerful piece of code. Not only will it generate you a list of links but it will also surround some text with span tags and you can add custom attributes to these albeit by using three nested arrays. To simplify this process and be more consistent with other elements for example row, header or cell you can now also add attributes right next to title and href or use the old way of combining them in an attribute array.

ex:

     $output = theme('links', array(array(
                'title' => t('span'),
                'href' => 'testthemepatch/test',
                'class' => 'modules-heading',
                'style' => 'font-weight : bold;'
                )
        ));
    return $output;

In stead of:

     $output = theme('links', array(array(
                'title' => t('span'),
                'href' => 'testthemepatch/test',
                'attributes' => array(
                        'class' => 'modules-heading',
                        'style' => 'font-weight : bold;')
                )
        ));
    return $output;

Your comments and suggestions are welcomed and appreciated.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nickl’s picture

Here is a test case module to test past and new functionality.

nickl’s picture

FileSize
1.53 KB

After review by Morbus we have decided to remove the multiple options and only use boolean true in aim of consistency for tagging a cell as a header.

This is the only valid option now:

    $cells[] = array('data' => 'Cell 1', 'header' => true);
    $cells[] = array('data' => 'Cell 2', 'header' => true);
    $cells[] = array('data' => 'Cell 3', 'header' => true);
   
    $rows[] = array(
        'data' =>    $cells,
        'style' => 'font-weight : bold;'
    );
  return theme('table',array(),$rows);
nickl’s picture

Test case examples updated.

nickl’s picture

FileSize
1.3 KB

More cosmetic changes and me not following standards. *sigh*

Morbus Iff’s picture

I'm all for the 'header' addition. Not so much for the theme_links change. (To repeat from IRC: "i think part of the problem is that attributes allows us not to whitelist all our known parameters. if we, for instance, add a "style" attribute to theme_links in the future, there'd be a huge problem if someone wanted to add a CSS style. since theyre'd be a namepsace clash. i think the determination has been "useful and required things are non-attributes" and "everything else is inside attributes". that way, we have a split namespace between need and want.)

So +1 to the header thing, -1 to the theme_links change. To demonstrate the header thing, you could fix up the watchdog log display (admin/log/event/1234), though you'll probably have to add a new CSS style for #watchdog th, since the th will be inherited with a bottom border which'll look retarded on that page.

nickl’s picture

FileSize
685 bytes

New patch file for table header approved fix.

adrian’s picture

+1 .. this is a decent patch , and a necessary approach.

adrian’s picture

Status: Needs review » Reviewed & tested by the community

ready to be committed.

Steven’s picture

Status: Reviewed & tested by the community » Fixed

Committed a shorter patch to HEAD which also documents this feature in the doxygen.

Anonymous’s picture

Status: Fixed » Closed (fixed)