protected function Grid::CreateGrids in Filebrowser 8.2
Same name and namespace in other branches
- 3.x src/Grid/Grid.php \Drupal\filebrowser\Grid\Grid::CreateGrids()
1 call to Grid::CreateGrids()
- Grid::get in src/Grid/Grid.php
File
- src/Grid/Grid.php, line 42
Class
- Grid
Namespace
Drupal\filebrowser\Grid
Code
protected function CreateGrids() {
$options = $this->options;
$horizontal = $options['alignment'] === 'horizontal';
$columns = $options['columns'];
$row = 0;
$col = 0;
$items = [];
$remainders = count($this->variables) % $columns;
$num_rows = floor(count($this->variables) / $columns);
$this->options['column_width'] = 100 / $columns;
foreach ($this->variables as $index => $item) {
if ($horizontal) {
$items[$row]['row'][$col]['content'] = $item;
}
else {
}
if (!$horizontal || $horizontal && empty($items[$row]['attributes'])) {
$row_attributes = [
'class' => [],
];
if (!empty($row_class)) {
$row_attributes['class'] = array_merge($row_attributes['class'], $row_class);
}
if ($horizontal) {
$items[$row]['attributes'] = new Attribute($row_attributes);
}
else {
$items[$col]['content'][$row]['attributes'] = new Attribute($row_attributes);
}
}
if ($horizontal || !$horizontal && empty($items[$col]['attributes'])) {
$col_attributes = [
'class' => [],
];
if (!empty($col_class)) {
$col_attributes['class'] = array_merge($col_attributes['class'], $col_class);
}
$col_attributes['style'] = 'width: ' . 100 / $options['columns'] . '%;';
if ($horizontal) {
$items[$row]['row'][$col]['content']['attributes'] = new Attribute($col_attributes);
}
else {
$items[$col]['attributes'] = new Attribute($col_attributes);
}
}
if ($horizontal) {
if ($col == 0 && $col != $options['columns'] - 1) {
$col++;
}
elseif ($col >= $options['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--;
}
}
}
$this->sortedGrids = $items;
}