You are here

public function SlickManager::preRender in Slick Carousel 7.3

Builds the Slick instance as a structured array ready for ::renderer().

File

src/SlickManager.php, line 320

Class

SlickManager
Implements SlickManagerInterface.

Namespace

Drupal\slick

Code

public function preRender(array $element) {
  $build = $element['#build'];
  unset($element['#build']);
  $settings =& $build['settings'];
  $settings += SlickDefault::htmlSettings();

  // Adds helper class if thumbnail on dots hover provided.
  // The thumbnail_style is provided by formatter, thumbnail by Slick Views.
  if (!empty($settings['thumbnail_effect']) && (!empty($settings['thumbnail_style']) || !empty($settings['thumbnail']))) {
    $dots_class[] = 'slick-dots--thumbnail-' . $settings['thumbnail_effect'];
  }

  // Adds dots skin modifier class if provided.
  if (!empty($settings['skin_dots'])) {
    $dots_class[] = 'slick-dots--' . str_replace('_', '-', $settings['skin_dots']);
  }

  // Merge dot classes with the custom defined at optionset.
  if (isset($dots_class) && !empty($build['optionset'])) {
    $dots_class[] = $build['optionset']
      ->getSetting('dotsClass') ?: 'slick-dots';
    $js['dotsClass'] = implode(" ", $dots_class);
  }

  // Overrides common options to re-use an optionset.
  if ($settings['display'] == 'main') {
    if (!empty($settings['override'])) {
      foreach ($settings['overridables'] as $key => $override) {
        $js[$key] = empty($override) ? FALSE : TRUE;
      }
    }

    // Hijack items, and build the Slick grid if so configured.
    if (!empty($settings['grid']) && !empty($settings['visible_items'])) {
      $build['items'] = $this
        ->buildGrid($build['items'], $settings);
    }
  }
  $build['attributes'] = $this
    ->prepareAttributes($build);
  $build['options'] = isset($js) ? array_merge($build['options'], $js) : $build['options'];
  drupal_alter('slick_optionset', $build['optionset'], $settings);

  // Pass the array to render array.
  foreach (SlickDefault::themeProperties() as $key) {
    $element["#{$key}"] = $build[$key];
  }
  unset($build);
  return $element;
}