From 6ac1d47a27931035e2fdc79413aeed4ba474e03f Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Fri, 24 May 2013 10:24:22 -0700 Subject: [PATCH] Issue #1843766 by joelpittet: Convert views/templates/views-view-table.tpl.php to twig. --- .../templates/views-view-table.html.twig | 54 +++++++++++++++++++ .../views/templates/views-view-table.tpl.php | 48 ----------------- core/modules/views/views.theme.inc | 48 +++++++++-------- 3 files changed, 81 insertions(+), 69 deletions(-) create mode 100644 core/modules/views/templates/views-view-table.html.twig delete mode 100644 core/modules/views/templates/views-view-table.tpl.php diff --git a/core/modules/views/templates/views-view-table.html.twig b/core/modules/views/templates/views-view-table.html.twig new file mode 100644 index 00000000000..50ae9d68ae9 --- /dev/null +++ b/core/modules/views/templates/views-view-table.html.twig @@ -0,0 +1,54 @@ +{# +/** + * @file + * Default theme implementation for displaying a view as a table. + * + * Available variables: + * - attributes: Remaining HTML attributes for the element. + * - class: HTML classes that can be used to style contextually through CSS. + * - title : The title of this group of rows. + * - header: Header labels. + * - header_classes: HTML classes to apply to each header cell, indexed by + * the header's key. + * - rows: Table row items. Rows are keyed by row number, fields within rows + * are keyed by field ID. + * - field: Table data field ID. + * - content: Table data content. + * - row_classes: HTML classes to apply to each row, indexed by row number. + * This matches the index in rows. + * - field_classes: HTML classes to apply to each row, indexed by row number. + * This matches the index in columns and rows. + * + * @see template_preprocess() + * @see template_preprocess_views_view_table() + * + * @ingroup themeable + */ +#} + + {% if title is not empty %} + {{ title }} + {% endif %} + {% if header %} + + + {% for key, field in header %} + + {{ field }} + + {% endfor %} + + + {% endif %} + + {% for row_count, row in rows %} + + {% for field, content in row %} + + {{ content }} + + {% endfor %} + + {% endfor %} + + diff --git a/core/modules/views/templates/views-view-table.tpl.php b/core/modules/views/templates/views-view-table.tpl.php deleted file mode 100644 index 4d44d42a313..00000000000 --- a/core/modules/views/templates/views-view-table.tpl.php +++ /dev/null @@ -1,48 +0,0 @@ - -> - - - - - - - $label): ?> - - - - - - - $row): ?> - > - $content): ?> - - - - - -
scope="col"> - -
> - -
diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index 6113b3d4f53..4c3cab8e63c 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -429,44 +429,52 @@ 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 $vars + * An associative array containing: + * - view: A ViewExecutable object. + * - rows: The raw row data. */ function template_preprocess_views_view_table(&$vars) { - $view = $vars['view']; + $view = $vars['view']; - // We need the raw data for this grouping, which is passed in as $vars['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 $vars['rows'] // so that it can get rebuilt. // Store rows so that they may be used by further preprocess functions. - $result = $vars['result'] = $vars['rows']; + $result = $vars['result'] = $vars['rows']; $vars['rows'] = array(); $vars['field_classes'] = array(); $vars['header'] = array(); - $options = $view->style_plugin->options; - $handler = $view->style_plugin; + $options = $view->style_plugin->options; + $handler = $view->style_plugin; $default_row_class = isset($options['default_row_class']) ? $options['default_row_class'] : TRUE; $row_class_special = isset($options['row_class_special']) ? $options['row_class_special'] : TRUE; - $fields = &$view->field; - $columns = $handler->sanitize_columns($options['columns'], $fields); + $fields = &$view->field; + $columns = $handler->sanitize_columns($options['columns'], $fields); - $active = !empty($handler->active) ? $handler->active : ''; - $order = !empty($handler->order) ? $handler->order : 'asc'; + $active = !empty($handler->active) ? $handler->active : ''; + $order = !empty($handler->order) ? $handler->order : 'asc'; // A boolean variable which stores whether the table has a responsive class. $responsive = FALSE; - $query = tablesort_get_query_parameters(); + $query = tablesort_get_query_parameters(); if (isset($view->exposed_raw_input)) { $query += $view->exposed_raw_input; } 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. + // Create a second variable so we can easily find what fields we have and + // what the CSS classes should be. $vars['fields'][$field] = drupal_clean_css_identifier($field); if ($active == $field) { $vars['fields'][$field] .= ' active'; @@ -516,11 +524,10 @@ function template_preprocess_views_view_table(&$vars) { $vars['header_classes'][$field]['class'][] = $options['info'][$field]['responsive']; $responsive = TRUE; } - // Add a CSS align class to each field if one was set + // Add a CSS align class to each field if one was set. if (!empty($options['info'][$field]['align'])) { $vars['header_classes'][$field]['class'][] = drupal_clean_css_identifier($options['info'][$field]['align']); } - // Add a header label wrapper if one was selected. if ($vars['header'][$field]) { $element_label_type = $fields[$field]->element_label_type(TRUE, TRUE); @@ -528,17 +535,16 @@ function template_preprocess_views_view_table(&$vars) { $vars['header'][$field] = '<' . $element_label_type . '>' . $vars['header'][$field] . ''; } } - } - // Add a CSS align class to each field if one was set + // Add a CSS align class to each field if one was set. if (!empty($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) { - // Add field classes + // Add field classes. $vars['field_classes'][$field][$num] = array(); if ($fields[$field]->options['element_default_classes']) { $vars['field_classes'][$field][$num]['class'][] = 'views-field'; @@ -575,12 +581,12 @@ function template_preprocess_views_view_table(&$vars) { else { $vars['rows'][$num][$column] = ''; } - $vars['rows'][$num][$column] .= $field_output; } } - // Remove columns if the option is hide empty column is checked and the field is not empty. + // 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 ($vars['rows'] as $num => $columns) { @@ -639,7 +645,7 @@ function template_preprocess_views_view_table(&$vars) { $vars['attributes']['class'][] = 'cols-' . count($vars['header']); if (!empty($handler->options['summary'])) { - $vars['attributes_array'] = array('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