summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2013-05-24 17:27:49 (GMT)
committerAlex Pott2013-05-24 17:27:49 (GMT)
commitd39eace47f5c339421cb04927a7e84f5abb4c3b9 (patch)
treeb29cb5050f88f119bd69c237c88fe1c11579585d
parent571786124e25f426e416e32a300fe1dd3bdc4f73 (diff)
Issue #1843750 by jastraat, joelpittet, jpamental, FluxSauce, gollyg, shanethehat, mr.baileys: Convert views/templates/views-view-grid.tpl.php to twig.
-rw-r--r--core/modules/views/templates/views-view-grid.html.twig36
-rw-r--r--core/modules/views/templates/views-view-grid.tpl.php28
-rw-r--r--core/modules/views/views.theme.inc33
3 files changed, 51 insertions, 46 deletions
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 0000000..8ba3003
--- /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 %}
+ <h3>{{ title }}</h3>
+{% endif %}
+<table{{ attributes }}>
+ <tbody>
+ {% for row_number, columns in rows %}
+ <tr{{ row_classes[row_number] }}>
+ {% for column_number, item in columns %}
+ <td{{ column_classes[row_number][column_number] }}>
+ {{ item }}
+ </td>
+ {% endfor %}
+ </tr>
+ {% endfor %}
+ </tbody>
+</table>
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 43ba37b..0000000
--- a/core/modules/views/templates/views-view-grid.tpl.php
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php
-
-/**
- * @file
- * Default simple view template to display a rows in a grid.
- *
- * - $rows contains a nested array of rows. Each row contains an array of
- * columns.
- *
- * @ingroup views_templates
- */
-?>
-<?php if (!empty($title)) : ?>
- <h3><?php print $title; ?></h3>
-<?php endif; ?>
-<table <?php print $attributes; ?>>
- <tbody>
- <?php foreach ($rows as $row_number => $columns): ?>
- <tr <?php print $row_classes[$row_number]; ?>>
- <?php foreach ($columns as $column_number => $item): ?>
- <td <?php print $column_classes[$row_number][$column_number]; ?>>
- <?php print $item; ?>
- </td>
- <?php endforeach; ?>
- </tr>
- <?php endforeach; ?>
- </tbody>
-</table>
diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc
index 9c1974b..88499b3 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'];
}
}