commit 4ddebce31f396721edb87f15f1dfa1815ef35285 Author: Joel Pittet Date: Mon Apr 15 10:15:33 2013 -0700 revert to make this easier to see the changes for conversion... cleanup later diff --git a/core/modules/views/templates/views-view-table.html.twig b/core/modules/views/templates/views-view-table.html.twig index ed40796..1c8b34d 100644 --- a/core/modules/views/templates/views-view-table.html.twig +++ b/core/modules/views/templates/views-view-table.html.twig @@ -5,26 +5,23 @@ * * Available variables: * - attributes: Remaining HTML attributes for the element. - * - attributes.class: HTML classes that can be used to style contextually - * through CSS. - * - title : The title of this group of rows. May be empty. + * - class: HTML classes that can be used to style contextually through CSS. + * - title : The title of this group of rows. * - header: @todo. - * - header.label: Header labels. - * - header.attributes: Header HTML classes keyed by field id. - * - fields: An array of CSS IDs to use for each field id. - * - classes: A class or classes to apply to the table, based on settings. - * - row_classes: An array of classes to apply to each row, indexed by row - * number. This matches the index in rows. - * - rows: An array of row items. Each row is an array of content. - * rows are keyed by row number, fields within rows are keyed by field ID. - * - field.classes: HTML Classes to apply to each field, indexed by - * field id, then row number. This matches the index in rows. + * - label: Header labels. + * - attributes: Header HTML classes. + * - rows: Table row items. + * rows are keyed by row number, fields within rows are keyed by field ID. + * - field: Table data items. + * - classes: HTML classes to apply to each field, indexed by + * field id, then row number. This matches the index in rows. + * - row_classes: HTML classes to apply to each row, indexed by row number. + * This matches the index in rows. * * @see template_preprocess() * @see template_preprocess_views_view_table() * * @ingroup themeable - * @ingroup views_templates */ #} diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index bc29630..7fbc1b9 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -445,19 +445,26 @@ function template_preprocess_views_view_summary_unformatted(&$vars) { } /** - * Display a view as a table style. + * Prepares variables for Views table templates. + * + * Default template: views-view-table.html.twig. + * + * @param array $variables + * An associative array containing: + * - view: A View object. */ -function template_preprocess_views_view_table(&$variables) { - $view = $variables['view']; +function template_preprocess_views_view_table(&$vars) { + $view = $vars['view']; - // We need the raw data for this grouping, which is passed in as $variables['rows']. + // We need the raw data for this grouping, which is passed in + // as $vars['rows']. // However, the template also needs to use for the rendered fields. We - // therefore swap the raw data out to a new variable and reset $variables['rows'] + // therefore swap the raw data out to a new variable and reset $vars['rows'] // so that it can get rebuilt. // Store rows so that they may be used by further preprocess functions. - $result = $variables['result'] = $variables['rows']; - $variables['rows'] = array(); - $variables['header'] = array(); + $result = $vars['result'] = $vars['rows']; + $vars['rows'] = array(); + $vars['header'] = array(); $options = $view->style_plugin->options; $handler = $view->style_plugin; @@ -484,17 +491,17 @@ function template_preprocess_views_view_table(&$variables) { foreach ($columns as $field => $column) { // Create a second variable so we can easily find what fields we have and what the // CSS classes should be. - $variables['fields'][$field] = drupal_clean_css_identifier($field); + $vars['fields'][$field] = drupal_clean_css_identifier($field); if ($active == $field) { - $variables['fields'][$field] .= ' active'; + $vars['fields'][$field] .= ' active'; } // render the header labels if ($field == $column && empty($fields[$field]->options['exclude'])) { $label = check_plain(!empty($fields[$field]) ? $fields[$field]->label() : ''); - $variables['header'][$field] = new stdClass(); + $vars['header'][$field] = new stdClass(); if (empty($options['info'][$field]['sortable']) || !$fields[$field]->click_sortable()) { - $variables['header'][$field]->label = $label; + $vars['header'][$field]->label = $label; } else { $initial = !empty($options['info'][$field]['default_sort_order']) ? $options['info'][$field]['default_sort_order'] : 'asc'; @@ -515,69 +522,63 @@ function template_preprocess_views_view_table(&$variables) { 'attributes' => array('title' => $title), 'query' => $query, ); - $variables['header'][$field]->label = l($label, current_path(), $link_options); + $vars['header'][$field]->label = l($label, current_path(), $link_options); } - $variables['header'][$field]->attributes = new Attribute(array('class' => array())); + $vars['header'][$field]->attributes = new Attribute(array('class' => array())); // Set up the header label class. if ($fields[$field]->options['element_default_classes']) { - $variables['header'][$field]->attributes['class'][] = 'views-field'; - $variables['header'][$field]->attributes['class'][] = 'views-field-' . $variables['fields'][$field]; + $vars['header'][$field]->attributes['class'][] = 'views-field'; + $vars['header'][$field]->attributes['class'][] = 'views-field-' . $vars['fields'][$field]; } $class = $fields[$field]->element_label_classes(0); if ($class) { - $variables['header'][$field]->attributes['class'][] = $class; + $vars['header'][$field]->attributes['class'][] = $class; } // Add responsive header classes. if (!empty($options['info'][$field]['responsive'])) { - $variables['header'][$field]->attributes['class'][] = $options['info'][$field]['responsive']; + $vars['header'][$field]->attributes['class'][] = $options['info'][$field]['responsive']; $responsive = TRUE; } // Add a CSS align class to each field if one was set. if (!empty($options['info'][$field]['align'])) { - $variables['header'][$field]->attributes['class'][] = drupal_clean_css_identifier($options['info'][$field]['align']); + $vars['header'][$field]->attributes['class'][] = drupal_clean_css_identifier($options['info'][$field]['align']); } // Add a header label wrapper if one was selected. - if ($variables['header'][$field]) { + if ($vars['header'][$field]) { $element_label_type = $fields[$field]->element_label_type(TRUE, TRUE); if ($element_label_type) { - $variables['header'][$field]->label = '<' . $element_label_type . '>' . $variables['header'][$field]->label . ''; + $vars['header'][$field]->label = '<' . $element_label_type . '>' . $vars['header'][$field]->label . ''; } } // Check if header label is not empty. - if (!empty($variables['header'][$field]->label)) { + if (!empty($vars['header'][$field]->label)) { $has_header_labels = TRUE; } } // Add a CSS align class to each field if one was set. if (!empty($options['info'][$field]['align'])) { - $variables['fields'][$field] .= ' ' . drupal_clean_css_identifier($options['info'][$field]['align']); + $vars['fields'][$field] .= ' ' . drupal_clean_css_identifier($options['info'][$field]['align']); } // Render each field into its appropriate column. foreach ($result as $num => $row) { - $content = ''; - if (!empty($variables['rows'][$num][$column])) { - $content = $variables['rows'][$num][$column]; - } - $variables['rows'][$num][$column] = new stdClass(); - $variables['rows'][$num][$column]->content = $content; - $variables['rows'][$num][$column]->attributes = new Attribute(array('class' => array())); + $vars['rows'][$num][$column]->attributes = new Attribute(array('class' => array())); // Add field classes. if ($fields[$field]->options['element_default_classes']) { - $variables['rows'][$num][$column]->attributes['class'][] = 'views-field'; - $variables['rows'][$num][$column]->attributes['class'][] = 'views-field-' . $variables['fields'][$field]; + $vars['rows'][$num][$column]->attributes['class'][] = 'views-field'; + $vars['rows'][$num][$column]->attributes['class'][] = 'views-field-' . $vars['fields'][$field]; } if ($classes = $fields[$field]->element_classes($num)) { - $variables['rows'][$num][$column]->attributes['class'][] = $classes; + $vars['rows'][$num][$column]->attributes['class'][] = $classes; } // Add responsive header classes. if (!empty($options['info'][$field]['responsive'])) { - $variables['rows'][$num][$column]->attributes['class'][] = $options['info'][$field]['responsive']; + $vars['rows'][$num][$column]->attributes['class'][] = $options['info'][$field]['responsive']; } if (!empty($fields[$field]) && empty($fields[$field]->options['exclude'])) { @@ -588,33 +589,33 @@ function template_preprocess_views_view_table(&$variables) { } // Don't bother with separators and stuff if the field does not show up. - if (empty($field_output) && !empty($variables['rows'][$num][$column]->content)) { + if (empty($field_output) && !empty($vars['rows'][$num][$column]->content)) { continue; } // Place the field into the column, along with an optional separator. - if (!empty($variables['rows'][$num][$column]->content)) { + if (!empty($vars['rows'][$num][$column]->content)) { if (!empty($options['info'][$column]['separator'])) { - $variables['rows'][$num][$column]->content .= filter_xss_admin($options['info'][$column]['separator']); + $vars['rows'][$num][$column]->content .= filter_xss_admin($options['info'][$column]['separator']); } } else { - $variables['rows'][$num][$column]->content = ''; + $vars['rows'][$num][$column]->content = ''; } - $variables['rows'][$num][$column]->content .= $field_output; + $vars['rows'][$num][$column]->content .= $field_output; } } // Remove columns if the option is hide empty column is checked and the field is not empty. if (!empty($options['info'][$field]['empty_column'])) { $empty = TRUE; - foreach ($variables['rows'] as $num => $columns) { + foreach ($vars['rows'] as $num => $columns) { $empty &= empty($columns[$column]); } if ($empty) { - foreach ($variables['rows'] as $num => &$column_items) { + foreach ($vars['rows'] as $num => &$column_items) { unset($column_items[$column]); - unset($variables['header'][$column]); + unset($vars['header'][$column]); } } } @@ -622,55 +623,55 @@ function template_preprocess_views_view_table(&$variables) { // Hide table header if all labels are empty. if (!$has_header_labels) { - $variables['header'] = array(); + $vars['header'] = array(); } $count = 0; - foreach ($variables['rows'] as $num => $row) { - $variables['row_classes'][$num] = array(); + foreach ($vars['rows'] as $num => $row) { + $vars['row_classes'][$num] = array(); if ($row_class_special) { - $variables['row_classes'][$num]['class'][] = ($count++ % 2 == 0) ? 'odd' : 'even'; + $vars['row_classes'][$num]['class'][] = ($count++ % 2 == 0) ? 'odd' : 'even'; if ($num === 0) { - $variables['row_classes'][$num]['class'][] = 'views-row-first'; + $vars['row_classes'][$num]['class'][] = 'views-row-first'; } - elseif ($num === (count($variables['rows']) - 1)) { - $variables['row_classes'][$num]['class'][] = 'views-row-last'; + elseif ($num === (count($vars['rows']) - 1)) { + $vars['row_classes'][$num]['class'][] = 'views-row-last'; } } if ($row_class = $handler->get_row_class($num)) { - $variables['row_classes'][$num]['class'][] = $row_class; + $vars['row_classes'][$num]['class'][] = $row_class; } - $variables['row_classes'][$num] = new Attribute($variables['row_classes'][$num]); + $vars['row_classes'][$num] = new Attribute($vars['row_classes'][$num]); } - $variables['attributes']['class'][] = 'views-table'; - if (empty($variables['rows']) && !empty($options['empty_table'])) { - $variables['rows'][0][0] = new stdClass(); - $variables['rows'][$num][$column]->content = $view->display_handler->renderArea('empty'); + $vars['attributes']['class'][] = 'views-table'; + if (empty($vars['rows']) && !empty($options['empty_table'])) { + $vars['rows'][0][0] = new stdClass(); + $vars['rows'][$num][$column]->content = $view->display_handler->renderArea('empty'); // Calculate the amounts of rows with output. - $variables['rows'][$num][$column]->attributes = new Attribute(array( - 'colspan' => count($variables['header']), + $vars['rows'][$num][$column]->attributes = new Attribute(array( + 'colspan' => count($vars['header']), 'class' => 'views-empty', )); } if (!empty($options['sticky'])) { - $variables['view']->element['#attached']['library'][] = array('system', 'drupal.tableheader'); - $variables['attributes']['class'][] = "sticky-enabled"; + $vars['view']->element['#attached']['library'][] = array('system', 'drupal.tableheader'); + $vars['attributes']['class'][] = "sticky-enabled"; } - $variables['attributes']['class'][] = 'cols-' . count($variables['header']); + $vars['attributes']['class'][] = 'cols-' . count($vars['header']); if (!empty($handler->options['summary'])) { - $variables['attributes']['summary'] = $handler->options['summary']; + $vars['attributes']['summary'] = $handler->options['summary']; } // 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($variables['header']) && $responsive) { - $variables['view']->element['#attached']['library'][] = array('system', 'drupal.tableresponsive'); + if (count($vars['header']) && $responsive) { + $vars['view']->element['#attached']['library'][] = array('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. - $variables['attributes']['class'][] = 'responsive-enabled'; + $vars['attributes']['class'][] = 'responsive-enabled'; } }