diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 05690f3..5b7bc50 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -2163,10 +2163,9 @@ function theme_table($variables) { * @todo: update this once merged with head, and table.html.twig updated. */ function template_preprocess_table(&$variables) { - // Flags. - $is_sticky = $variables['sticky']; - $is_responsive = $variables['responsive']; + $is_sticky = !empty($variables['sticky']); + $is_responsive = !empty($variables['responsive']); // Table attributes. // Note: Cast to Attribute() at the bottom. @@ -2179,11 +2178,14 @@ function template_preprocess_table(&$variables) { // header after it's cells are processed // array_values indexes for the table sort to work // @todo: Clarify why this variable is used or fix to use variables['header'] directly. - $headers = $variables['header'] = array_values($variables['header']); + if (!empty($variables['header']) && is_array($variables['header'])) { + $variables['header'] = array_values($variables['header']); + } + $headers = $variables['header']; // Empty message. // Set to new variable for convenient checks later. - $empty_message = $variables['empty']; + $empty_message = (isset($variables['empty'])) ? $variables['empty'] : ''; // Remove 'empty' from template variables and set message to it's own variable // to make sure we don't conflict with Twig's reserved keyword of the same name. unset($variables['empty']); @@ -2286,10 +2288,15 @@ function template_preprocess_table(&$variables) { if (!is_array($cell)) { $cell = array( 'data' => $cell, - 'attributes' => new Attribute(array()), + 'attributes' => array(), ); } + // Create cell attributes + if (!isset($cell['attributes'])) { + $cell['attributes'] = array(); + } + // Track responsive classes for each column as needed. Only the header // cells for a column are marked up with the responsive classes by a // module developer or themer. The responsive classes on the header cells @@ -2301,17 +2308,20 @@ function template_preprocess_table(&$variables) { elseif (in_array(RESPONSIVE_PRIORITY_LOW, $cell['class'])) { $responsive_classes[$col_key] = RESPONSIVE_PRIORITY_LOW; } - - // Move cell 'class' into 'attributes'. - // @todo: API change so 'class' is already within 'attributes'. - $cell['attributes']['class'] = $cell['class']; - unset($cell['class']); } // @todo: Find out why we can use $variables['header'] here but must use // $headers for tablesort_cell() below. $cell = tablesort_header($cell, $variables['header'], $ts); + // Support simple or complex cells. + // Doing this after tablesort_header because it removes it's sort and field values + foreach ($cell as $key => $value) { + if ($key != 'data' && $key != 'attributes') { + $cell['attributes'][$key] = $value; + } + } + // Flag the cell as a header. $cell['header'] = TRUE; @@ -2372,9 +2382,18 @@ function template_preprocess_table(&$variables) { $variables['rows'][$row_key]['cells'] = array(); $i = 0; foreach ($cells as $cell) { + // If the cell is not an array, make it one. if (!is_array($cell)) { - $cell = array('data' => $cell); + $cell = array( + 'data' => $cell, + 'attributes' => array(), + ); + } + + // Create cell attributes + if (!isset($cell['attributes'])) { + $cell['attributes'] = array(); } // Add active class if needed for sortable tables. @@ -2382,6 +2401,13 @@ function template_preprocess_table(&$variables) { // instead of $headers here while we can in tablesort_header() above. $cell = tablesort_cell($cell, $headers, $ts, $i); + // Support simple or complex cells. + foreach ($cell as $key => $value) { + if ($key != 'data' && $key != 'attributes') { + $cell['attributes'][$key] = $value; + } + } + // Copy RESPONSIVE_PRIORITY_LOW/RESPONSIVE_PRIORITY_MEDIUM // class from header to cell as needed. if (isset($responsive_classes[$i])) { @@ -2843,7 +2869,8 @@ function template_preprocess_table_cell(&$variables) { $variables['content'] = ''; if (empty($variables['attributes'])) { $variables['attributes'] = new Attribute(); - } else { + } + else { $variables['attributes'] = new Attribute($variables['attributes']); } diff --git a/core/themes/stark/templates/theme.inc/table.html.twig b/core/themes/stark/templates/theme.inc/table.html.twig index 95a5082..c3ef088 100644 --- a/core/themes/stark/templates/theme.inc/table.html.twig +++ b/core/themes/stark/templates/theme.inc/table.html.twig @@ -7,13 +7,10 @@ * - attributes: HTML attributes to apply to the tag. * - caption: A localized string for the tag. - * - cols: a list of tag each with the following attributes: - * - attributes: HTML attributes to apply to the tag. - * - * Note: Drupal currently supports only one table header row. - * @see http://drupal.org/node/893530 - * @see http://api.drupal.org/api/drupal/includes!theme.inc/function/theme_table/7#comment-5109 + * - attributes: HTML attributes to apply to the tag. + * // Note: Drupal currently supports only one table header row. + * // @see http://drupal.org/node/893530 + * // @see http://api.drupal.org/api/drupal/includes!theme.inc/function/theme_table/7#comment-5109 * - header: Table header cells. Each cell contains the following properties: * - attributes: HTML attributes to apply to the tag. * - data: Table cells. * - no_striping: a flag indicating that the row should receive no - * 'even / odd' styling. Defaults to FALSE. - * @todo: Deprecate no_striping? http://drupal.org/node/1192156 + * 'even / odd' styling. Defaults to FALSE. // @todo: Deprecate no_striping? * A cell can be either a string or may contain the following keys: * - data: The string to display in the table cell. * - header: Indicates this cell is a header. @@ -50,16 +46,8 @@ {% for colgroup in colgroups %} {% if colgroup.cols %} - {# - Temporary Fix by http://drupal.org/node/1778968#comment-6820122 - col.attributes is getting stripped on second loop through - prefer this: - {% for col in colgroup.cols %} - - {% endfor %} - #} - {% for i,col in colgroup.cols %} - + {% for col in colgroup.cols %} + {% endfor %} {% else %}
tag. * - colgroups: Column groups. Each group contains the following properties: - * - attributes: HTML attributes to apply to the
tag. * - data: A localized string for the title of the column. @@ -24,8 +21,7 @@ * - attributes: HTML attributes to apply to the