You are here

public function SlickManager::preRenderSlickWrapper in Slick Carousel 8.2

Same name and namespace in other branches
  1. 8 src/SlickManager.php \Drupal\slick\SlickManager::preRenderSlickWrapper()

One slick_theme() to serve multiple displays: main, overlay, thumbnail.

File

src/SlickManager.php, line 327

Class

SlickManager
Implements BlazyManagerInterface, SlickManagerInterface.

Namespace

Drupal\slick

Code

public function preRenderSlickWrapper($element) {
  $build = $element['#build'];
  unset($element['#build']);

  // Prepare settings and assets.
  $this
    ->prepareSettings($element, $build);

  // Checks if we have thumbnail navigation.
  $thumbs = isset($build['thumb']) ? $build['thumb'] : [];
  $settings = $build['settings'];

  // Prevents unused thumb going through the main display.
  unset($build['thumb']);

  // Build the main Slick.
  $slick[0] = $this
    ->slick($build);

  // Build the thumbnail Slick.
  if ($settings['nav'] && $thumbs) {
    $slick[1] = $this
      ->buildNavigation($build, $thumbs);
  }

  // Reverse slicks if thumbnail position is provided to get CSS float work.
  if ($settings['navpos']) {
    $slick = array_reverse($slick);
  }

  // Collect the slick instances.
  $element['#items'] = $slick;
  $element['#cache'] = $this
    ->getCacheMetadata($build);
  unset($build);
  return $element;
}