You are here

public function SlickFormatter::preBuildElements in Slick Carousel 7.3

Same name and namespace in other branches
  1. 8.2 src/SlickFormatter.php \Drupal\slick\SlickFormatter::preBuildElements()

Overrides BlazyFormatter::preBuildElements

File

src/SlickFormatter.php, line 30

Class

SlickFormatter
Implements SlickFormatterInterface.

Namespace

Drupal\slick

Code

public function preBuildElements(array &$build, $items, $entity, array $entities = []) {
  parent::preBuildElements($build, $items, $entity, $entities);
  $settings =& $build['settings'];

  // Load the optionset to work with.
  $optionset = Slick::loadWithFallback($settings['optionset']);

  // Defines settings which should reach container and down to each item here.
  $settings['nav'] = !empty($settings['optionset_thumbnail']) && isset($items[1]);

  // Do not bother for SlickTextFormatter, or when vanilla is on.
  if (empty($settings['vanilla'])) {
    $lazy = $optionset
      ->getSetting('lazyLoad');
    $settings['blazy'] = $lazy == 'blazy' || !empty($settings['blazy']);
    $settings['lazy'] = $settings['blazy'] ? 'blazy' : $lazy;
    if (empty($settings['blazy'])) {
      $settings['lazy_class'] = $settings['lazy_attribute'] = 'lazy';
    }
  }
  else {

    // Nothing to work with Vanilla on, disable the asnavfor, else JS error.
    $settings['nav'] = FALSE;
  }

  // Only trim overridables options if disabled.
  if (empty($settings['override']) && isset($settings['overridables'])) {
    $settings['overridables'] = array_filter($settings['overridables']);
  }
  $build['optionset'] = $optionset;
  drupal_alter('slick_settings', $build, $items);
}