commit d3fefbe694d3c254a9409c014510e12ccd8e5049 Author: Ben Alman Date: Sat Mar 29 01:10:07 2014 -0700 cleanup and fixes diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 12f9b56..7b236ea 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1537,13 +1537,15 @@ function theme_table($variables) { // HTML requires that the thead tag has tr tags in it followed by tbody // tags. Using ternary operator to check and see if we have any rows. $output .= (count($rows) ? ' ' : ' '); - foreach ($header as $i => $cell) { + $i = 0; + foreach ($header as $cell) { + $i++; // If the cell is not an array, make it one. if (!is_array($cell)) { $cell = array('data' => $cell); } $cell['data'] = isset($cell['data']) ? $cell['data'] : ''; - $cell['attributes'] = isset($cell['attributes']) ? $cell['data'] : array(); + $cell['attributes'] = isset($cell['attributes']) ? $cell['attributes'] : array(); // Flag the cell as a header or not and remove the flag. $is_header = isset($cell['header']) ? $cell['header'] : TRUE; @@ -1566,11 +1568,9 @@ function theme_table($variables) { // Move cell properties that are not data or attributes into attributes. // Doing this after tablesort_header because it removes the sort and field // keys. - foreach ($cell as $key => $value) { - if ($key != 'data' && $key != 'attributes') { - $cell['attributes'][$key] = $value; - } - } + $cell['attributes'] = array_diff_key($cell, array_flip(array('data', 'attributes'))) + $cell['attributes']; + + // Cell's data property can be a string or a renderable array. if (is_array($cell['data'])) { $cell['data'] = drupal_render($cell['data']); } @@ -1622,7 +1622,7 @@ function theme_table($variables) { $cell = array('data' => $cell); } $cell['data'] = isset($cell['data']) ? $cell['data'] : ''; - $cell['attributes'] = isset($cell['attributes']) ? $cell['data'] : array(); + $cell['attributes'] = isset($cell['attributes']) ? $cell['attributes'] : array(); // Flag the cell as a header or not and remove the flag. $is_header = !empty($cell['header']); @@ -1630,11 +1630,7 @@ function theme_table($variables) { // Move cell properties that are not data or attributes // into attributes. - foreach ($cell as $key => $value) { - if ($key != 'data' && $key != 'attributes') { - $cell['attributes'][$key] = $value; - } - } + $cell['attributes'] = array_diff_key($cell, array_flip(array('data', 'attributes'))) + $cell['attributes']; // Add active class if needed for sortable tables. if (isset($header[$i]['data']) && $header[$i]['data'] == $ts['name'] && !empty($header[$i]['field'])) { @@ -1645,6 +1641,7 @@ function theme_table($variables) { if (isset($responsive[$i])) { $cell['attributes']['class'][] = $responsive[$i]; } + // Cell's data property can be a string or a renderable array. if (is_array($cell['data'])) { $cell['data'] = drupal_render($cell['data']); }