diff --git a/core/modules/views/templates/views-view-grid.html.twig b/core/modules/views/templates/views-view-grid.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..8ba3003edf99e55cea95a78daf950c8a4fca2f6c --- /dev/null +++ b/core/modules/views/templates/views-view-grid.html.twig @@ -0,0 +1,36 @@ +{# +/** + * @file + * Default theme implementation for views to display rows in a grid. + * + * Available variables: + * - attributes: HTML attributes for the table element. + * - title: The title of this group of rows. + * - rows: A list of rows. Each row contains a list of columns. + * - row_classes: HTML classes for each row including the row number and first + * or last. + * - column_classes: HTML classes for each column including the row number and + * first or last. + * + * @see template_preprocess() + * @see template_preprocess_views_view_grid() + * + * @ingroup themeable + */ +#} +{% if title %} +

{{ title }}

+{% endif %} + + + {% for row_number, columns in rows %} + + {% for column_number, item in columns %} + + {{ item }} + + {% endfor %} + + {% endfor %} + + diff --git a/core/modules/views/templates/views-view-grid.tpl.php b/core/modules/views/templates/views-view-grid.tpl.php deleted file mode 100644 index 43ba37b12443393a110dbf17d8f8435b3f1eaaf6..0000000000000000000000000000000000000000 --- a/core/modules/views/templates/views-view-grid.tpl.php +++ /dev/null @@ -1,28 +0,0 @@ - - -

- -> - - $columns): ?> - > - $item): ?> - - - - - -
> - -
diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index 9c1974b94abb79c48a194d0d1c14919bc9099fbc..88499b37a40b13c5a7470ae295fec27b16e51042 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -659,17 +659,23 @@ function template_preprocess_views_view_table(&$vars) { } /** - * Display a view as a grid style. + * Prepares variables for views grid style templates. + * + * Default template: views-view-grid.html.twig. + * + * @param array $vars + * An associative array containing: + * - view: The view object. + * - rows: An array of row items. Each row is an array of content. */ function template_preprocess_views_view_grid(&$vars) { - $view = $vars['view']; - $result = $view->result; - $options = $view->style_plugin->options; - $handler = $view->style_plugin; + $view = $vars['view']; + $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; - $columns = $options['columns']; + $columns = $options['columns']; $vars['attributes']['class'][] = 'views-view-grid cols-' . $columns; $rows = array(); @@ -724,14 +730,14 @@ function template_preprocess_views_view_grid(&$vars) { } } for ($i = 0; $i < count($rows[0]); $i++) { - // This should be string so that's okay :) + // This should be a string so this is ok. if (!isset($rows[count($rows) - 1][$i])) { $rows[count($rows) - 1][$i] = ''; } } } - // Apply the row classes + // Apply the row classes. foreach ($rows as $row_number => $row) { $row_classes = array(); if ($default_row_class) { @@ -768,16 +774,7 @@ function template_preprocess_views_view_grid(&$vars) { } $vars['rows'] = $rows; if (!empty($handler->options['summary'])) { - $vars['attributes_array'] = array('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($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. - $vars['attributes']['class'][] = 'responsive-enabled'; + $vars['attributes']['summary'] = $handler->options['summary']; } }