You are here

public function SlickManager::buildGrid in Slick Carousel 8.2

Same name and namespace in other branches
  1. 8 src/SlickManager.php \Drupal\slick\SlickManager::buildGrid()
  2. 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 170

Class

SlickManager
Implements BlazyManagerInterface, SlickManagerInterface.

Namespace

Drupal\slick

Code

public 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;
    $grids[0] = $this
      ->buildGridItem($items, 0, $settings);
  }
  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) {
      $grids[] = $this
        ->buildGridItem($grid_item, $delta, $settings);
    }
  }
  return $grids;
}