Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 295277

Improve the theme_table API

$
0
0

The current theme_table API is a bit of a hack, in that it doesn't properly separate options from data. That causes issues like that the 'no_striping' option is printed as an HTML attribute, which is invalid (see: #1959110: theme_table outputs the no_striping option as an HTML attribute.). Also, it doesn't make sense to have a 'no_striping' option per row, it should just be globally applied to all rows. It could also be renamed to 'zebra_striping' and default to TRUE.
Other changes can be made to properly separate the HTML attributes in their own array, for both rows and cells. Ideally, the API should change from this:

<?php
// Old API.
$rows = array(
  array(
   
'data'=> array(
      array(
       
'data'=> 'This is a header cell',
       
'header'=> TRUE,
       
'class'=> array('cell-class-1', 'cell-class-2'),
      ),
     
'Cell 2',
    ),
   
'no_striping'=> TRUE,
   
'class'=> array('row-class-1', 'row-class-2'),
  ),
  array(
'Cell 3', 'Cell 4'),
);
?>

To this:

<?php
// New API.
$rows = array(
 
'zebra_striping'=> FALSE,
 
'data'=> array(
    array(
     
'data'=> array(
        array(
         
'data'=> 'This is a header cell',
         
'header'=> TRUE,
         
'attributes'=> array(
           
'class'=> array('cell-class-1', 'cell-class-2'),
          ),
        ),
       
'Cell 2',
      ),
     
'attributes'=> array(
       
'class'=> array('row-class-1', 'row-class-2'),
      ),
    ),
    array(
'Cell 3', 'Cell 4'),
  ),
);
?>

This moves all the HTML attributes to their own 'attributes' array, which is also common in other theme functions, and removes the 'no_striping' option in favor of a 'zebra_striping' option in the root of the $rows array.


Viewing all articles
Browse latest Browse all 295277

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>