diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index 45d0748..0827ba7 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -2234,60 +2234,198 @@ function drupal_pre_render_table(array $element) {
function theme_table($variables) {
$header = $variables['header'];
$rows = $variables['rows'];
- $table_attributes = $variables['attributes'];
+ $attributes = $variables['attributes'];
$caption = $variables['caption'];
$colgroups = $variables['colgroups'];
+ $sticky = $variables['sticky'];
+ $responsive = $variables['responsive'];
+ $empty = $variables['empty'];
- $output = '
\n";
+ // Add sticky headers, if applicable.
+ if (count($header) && $sticky) {
+ drupal_add_library('system', 'drupal.tableheader');
+ // Add 'sticky-enabled' class to the table to identify it for JS.
+ // This is needed to target tables constructed by this function.
+ $attributes['class'][] = 'sticky-enabled';
+ }
+ // If the table has headers and it should react responsively to columns hidden
+ // with the classes represented by the constants RESPONSIVE_PRIORITY_MEDIUM
+ // and RESPONSIVE_PRIORITY_LOW, add the tableresponsive behaviors.
+ if (count($header) && $responsive) {
+ drupal_add_library('system', 'drupal.tableresponsive');
+ // Add 'responsive-enabled' class to the table to identify it for JS.
+ // This is needed to target tables constructed by this function.
+ $attributes['class'][] = 'responsive-enabled';
+ }
+
+ $output = '\n";
if (isset($caption)) {
$output .= '' . $caption . "\n";
}
// Format the table columns:
- if (!empty($colgroups)) {
- foreach ($colgroups as $colgroup_key => $colgroup) {
+ if (count($colgroups)) {
+ foreach ($colgroups as $number => $colgroup) {
+ $attributes = array();
+
+ // Check if we're dealing with a simple or complex column
+ if (isset($colgroup['data'])) {
+ foreach ($colgroup as $key => $value) {
+ if ($key == 'data') {
+ $cols = $value;
+ }
+ else {
+ $attributes[$key] = $value;
+ }
+ }
+ }
+ else {
+ $cols = $colgroup;
+ }
// Build colgroup
- if (is_array($colgroup['cols']) && !empty($colgroup['cols'])) {
- $output .= ' ';
- foreach ($colgroup['cols'] as $col) {
- $output .= ' ';
+ if (is_array($cols) && count($cols)) {
+ $output .= ' ';
+ $i = 0;
+ foreach ($cols as $col) {
+ $output .= ' ';
}
$output .= " \n";
}
else {
- $output .= ' \n";
+ $output .= ' \n";
}
}
}
+ // Add the 'empty' row message if available.
+ if (!count($rows) && $empty) {
+ $header_count = 0;
+ foreach ($header as $header_cell) {
+ if (is_array($header_cell)) {
+ $header_count += isset($header_cell['colspan']) ? $header_cell['colspan'] : 1;
+ }
+ else {
+ $header_count++;
+ }
+ }
+ $rows[] = array(array('data' => $empty, 'colspan' => $header_count, 'class' => array('empty', 'message')));
+ }
+
+ $responsive = array();
// Format the table header:
- if (!empty($header)) {
+ if (count($header)) {
+ $ts = tablesort_init($header);
// 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 .= (!empty($rows) ? ' ' : '
');
+ $output .= (count($rows) ? ' ' : '
');
+ $i = 0;
foreach ($header as $cell) {
- $output .= theme('table_cell', $cell);
+ $i++;
+
+ if (!is_array($cell)) {
+ $cell = array('data' => $cell, 'attributes' => new Attribute());
+ }
+ else {
+ if (!isset($cell['data'])) {
+ $cell['data'] = '';
+ }
+ // 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
+ // must be transferred to the content cells.
+ if (!empty($cell['class']) && is_array($cell['class'])) {
+ if (in_array(RESPONSIVE_PRIORITY_MEDIUM, $cell['class'])) {
+ $responsive[$i] = RESPONSIVE_PRIORITY_MEDIUM;
+ }
+ elseif (in_array(RESPONSIVE_PRIORITY_LOW, $cell['class'])) {
+ $responsive[$i] = RESPONSIVE_PRIORITY_LOW;
+ }
+ }
+ $cell = tablesort_header($cell, $header, $ts);
+ // @todo Refactor this so that attributes are not top-level.
+ $_cell = $cell;
+ unset($_cell['data']);
+ unset($_cell['header']);
+ $cell['attributes'] = new Attribute($_cell);
+ }
+
+ $output .= '| ';
+ $output .= is_array($cell['data']) ? drupal_render($cell['data']) : $cell['data'];
+ $output .= ' | ';
}
// Using ternary operator to close the tags based on whether or not there are rows
- $output .= (!empty($rows) ? "
\n" : "
\n");
+ $output .= (count($rows) ? " \n" : "\n");
}
else {
$ts = array();
}
// Format the table rows:
- if (!empty($rows)) {
+ if (count($rows)) {
$output .= "\n";
- foreach ($rows as $row) {
- $cells = $row['cells'];
- if (!empty($cells)) {
+ $flip = array('even' => 'odd', 'odd' => 'even');
+ $class = 'even';
+ foreach ($rows as $number => $row) {
+ $attributes = array();
+
+ // Check if we're dealing with a simple or complex row
+ if (isset($row['data'])) {
+ foreach ($row as $key => $value) {
+ if ($key == 'data') {
+ $cells = $value;
+ }
+ else {
+ $attributes[$key] = $value;
+ }
+ }
+ }
+ else {
+ $cells = $row;
+ }
+ if (count($cells)) {
+ // Add odd/even class
+ if (empty($row['no_striping'])) {
+ $class = $flip[$class];
+ $attributes['class'][] = $class;
+ }
// Build row
- $output .= ' ';
+ $output .= '
';
+ $i = 0;
foreach ($cells as $cell) {
- $output .= theme('table_cell', $cell);
+ $i++;
+
+ if (!is_array($cell)) {
+ $cell = array('data' => $cell, 'attributes' => new Attribute());
+ // Add responsive class.
+ if (isset($responsive[$i])) {
+ $cell['attributes']['class'] = array($responsive[$i]);
+ }
+ }
+ else {
+ if (!isset($cell['data'])) {
+ $cell['data'] = '';
+ }
+ $cell = tablesort_cell($cell, $header, $ts, $i);
+ // @todo Refactor this so that attributes are not top-level.
+ $_cell = $cell;
+ unset($_cell['data']);
+ unset($_cell['header']);
+ $cell['attributes'] = new Attribute($_cell);
+ // Add responsive class.
+ if (isset($responsive[$i])) {
+ if (!is_array($cell['attributes']['class'])) {
+ $cell['attributes']['class'] = array();
+ }
+ $cell['attributes']['class'][] = $responsive[$i];
+ }
+ }
+
+ $output .= '| ';
+ $output .= is_array($cell['data']) ? drupal_render($cell['data']) : $cell['data'];
+ $output .= ' | ';
}
$output .= "
\n";
}
@@ -2992,63 +3130,10 @@ function theme_indentation($variables) {
}
/**
- * Returns HTML for a table cell.
- *
- * @param $variables
- * An associative array containing:
- * header: Whether this cell is a header cell or not.
- * content: The cell content.
- * attributes: HTML attributes to apply to the cell.
- */
-function theme_table_cell($variables) {
- $is_header = $variables['header'];
- $content = (isset($variables['content'])) ? $variables['content'] : '';
- $attributes = (isset($variables['attributes'])) ? $variables['attributes'] : '';
-
- if ($is_header) {
- $output = '' . $content . ' | ';
- }
- else {
- $output = '' . $content . ' | ';
- }
- return $output;
-}
-
-
-/**
* @} End of "addtogroup themeable".
*/
/**
- * Preprocess variables for theme_table_cell().
- */
-function template_preprocess_table_cell(&$variables) {
-
- // Initialize variables needed by template
- $variables['header'] = isset($variables['header']) || FALSE;
- $variables['content'] = '';
- if (empty($variables['attributes'])) {
- $variables['attributes'] = new Attribute();
- }
- else {
- $variables['attributes'] = new Attribute($variables['attributes']);
- }
-
- // Cells can be arrays or strings.
- if (isset($variables['data'])) {
- // The cell's data element can be a render array or a string.
- if (is_array($variables['data'])) {
- $variables['content'] = drupal_render($variables['data']);
- }
- else {
- $variables['content'] = $variables['data'];
- }
- // Unset the data element to avoid it appearing in the attributes.
- unset($variables['data']);
- }
-}
-
-/**
* Adds a default set of helper variables for variable processors and templates.
*
* This function is called for theme hooks implemented as templates only, not
@@ -3637,9 +3722,6 @@ function drupal_common_theme() {
'table' => array(
'variables' => array('header' => NULL, 'rows' => NULL, 'attributes' => array(), 'caption' => NULL, 'colgroups' => array(), 'sticky' => TRUE, 'responsive' => TRUE, 'empty' => ''),
),
- 'table_cell' => array(
- 'variables' => array('content' => NULL, 'header' => NULL, 'attributes' => array()),
- ),
'meter' => array(
'variables' => array('display_value' => NULL, 'form' => NULL, 'high' => NULL, 'low' => NULL, 'max' => NULL, 'min' => NULL, 'optimum' => NULL, 'value' => NULL, 'percentage' => NULL, 'attributes' => array()),
),
diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module
index 87d59c2..3b82dc6 100644
--- a/core/modules/forum/forum.module
+++ b/core/modules/forum/forum.module
@@ -6,6 +6,7 @@
*/
use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Template\Attribute;
use Drupal\node\Plugin\Core\Entity\Node;
use Drupal\entity\Plugin\Core\Entity\EntityDisplay;
use Drupal\taxonomy\Plugin\Core\Entity\Term;
@@ -1125,7 +1126,12 @@ function template_preprocess_forum_topic_list(&$variables) {
$header = '';
foreach ($forum_topic_list_header as $cell) {
$cell = tablesort_header($cell, $forum_topic_list_header, $ts);
- $header .= theme('table_cell', array('cell' => $cell, 'header' => TRUE));
+ // @todo Refactor this so that attributes are not top-level.
+ // @see theme_table
+ $_cell = $cell;
+ unset($_cell['data']);
+ $cell['attributes'] = new Attribute($_cell);
+ $header .= "" . drupal_render($cell['data']) . " | ";
}
$variables['header'] = $header;