Commit d39eace4 authored by alexpott's avatar alexpott

Issue #1843750 by jastraat, joelpittet, jpamental, FluxSauce, gollyg,...

Issue #1843750 by jastraat, joelpittet, jpamental, FluxSauce, gollyg, shanethehat, mr.baileys: Convert views/templates/views-view-grid.tpl.php to twig.
parent 57178612
{#
/**
* @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>
<?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>
......@@ -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'];
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment