public static function SlickManager::buildGrid in Slick Carousel 8
Same name and namespace in other branches
- 8.2 src/SlickManager.php \Drupal\slick\SlickManager::buildGrid()
- 7.3 src/SlickManager.php \Drupal\slick\SlickManager::buildGrid()
Returns items as a grid display.
1 call to SlickManager::buildGrid()
- SlickManager::preRenderSlick in src/
SlickManager.php - Builds the Slick instance as a structured array ready for ::renderer().
File
- src/
SlickManager.php, line 294
Class
- SlickManager
- Implements BlazyManagerInterface, SlickManagerInterface.
Namespace
Drupal\slickCode
public static function buildGrid(array $items = [], array &$settings = []) {
$grids = [];
// Enforces unslick with less items.
if (empty($settings['unslick']) && !empty($settings['count'])) {
$settings['unslick'] = $settings['count'] < $settings['visible_items'];
}
// Display all items if unslick is enforced for plain grid to lightbox.
// Or when the total is less than visible_items.
if (!empty($settings['unslick'])) {
$settings['display'] = 'main';
$settings['current_item'] = 'grid';
$settings['count'] = 2;
$slide['slide'] = [
'#theme' => 'slick_grid',
'#items' => $items,
'#delta' => 0,
'#settings' => $settings,
];
$slide['settings'] = $settings;
$grids[0] = $slide;
}
else {
// Otherwise do chunks to have a grid carousel, and also update count.
$preserve_keys = !empty($settings['preserve_keys']);
$grid_items = array_chunk($items, $settings['visible_items'], $preserve_keys);
$settings['count'] = count($grid_items);
foreach ($grid_items as $delta => $grid_item) {
$slide = [];
$slide['slide'] = [
'#theme' => 'slick_grid',
'#items' => $grid_item,
'#delta' => $delta,
'#settings' => $settings,
];
$slide['settings'] = $settings;
$grids[] = $slide;
unset($slide);
}
}
return $grids;
}