function _views_bootstrap_split_rows in Views Bootstrap 7.2
Split items by rows and columns.
- Stolen from Drupal 8 template_preprocess_views_view_grid().
@TODO: Use array_chunk().
Parameters
$vars:
$columns:
bool $horizontal:
Return value
array
2 calls to _views_bootstrap_split_rows()
- template_preprocess_views_bootstrap_grid_plugin_style in templates/
grid/ theme.inc - Implementation of template preprocess for the view.
- template_preprocess_views_bootstrap_thumbnail_plugin_style in templates/
thumbnail/ theme.inc - Implementation of template preprocess for the view.
File
- ./
views_bootstrap.module, line 26 - Bootstrap integration.
Code
function _views_bootstrap_split_rows($vars, $columns, $horizontal = TRUE) {
$col = 0;
$row = 0;
$items = array();
$remainders = count($vars['rows']) % $columns;
$num_rows = floor(count($vars['rows']) / $columns);
// Iterate over each rendered views result row.
foreach ($vars['rows'] as $item) {
// Add the item.
if ($horizontal) {
$items[$row]['content'][$col]['content'] = $item;
}
else {
$items[$col]['content'][$row]['content'] = $item;
}
// Increase, decrease or reset appropriate integers.
if ($horizontal) {
if ($col == 0 && $col != $columns - 1) {
$col++;
}
elseif ($col >= $columns - 1) {
$col = 0;
$row++;
}
else {
$col++;
}
}
else {
$row++;
if (!$remainders && $row == $num_rows) {
$row = 0;
$col++;
}
elseif ($remainders && $row == $num_rows + 1) {
$row = 0;
$col++;
$remainders--;
}
}
}
return $items;
}