You are here

public function SlickManager::prepareAttributes in Slick Carousel 7.3

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

Prepare attributes for the known module features, not necessarily users'.

1 call to SlickManager::prepareAttributes()
SlickManager::preRender in src/SlickManager.php
Builds the Slick instance as a structured array ready for ::renderer().

File

src/SlickManager.php, line 255

Class

SlickManager
Implements SlickManagerInterface.

Namespace

Drupal\slick

Code

public function prepareAttributes(array $build = []) {
  $settings = $build['settings'];
  $attributes = isset($build['attributes']) ? $build['attributes'] : [];
  $classes = [];
  $skin = $settings['skin'];
  if ($skin) {
    $classes[] = 'skin--' . str_replace('_', '-', $skin);
    if (strpos($skin, 'boxed') !== FALSE) {
      $classes[] = 'skin--boxed';
    }
    if (strpos($skin, 'split') !== FALSE) {
      $classes[] = 'skin--split';
    }
  }
  if ($settings['nav']) {
    $classes[] = $settings['display'];
  }
  if ($settings['vertical']) {
    $classes[] = 'vertical';
  }
  if ($settings['optionset']) {
    $classes[] = 'optionset--' . str_replace('_', '-', $settings['optionset']);
  }
  if ($settings['display'] == 'main') {

    // Sniffs for Views to allow block__no_wrapper, views__no_wrapper, etc.
    // @todo use Blazy::containerAttributes($attributes, $settings);
    if ($settings['view_name'] && $settings['current_view_mode']) {
      $classes[] = 'view--' . str_replace('_', '-', $settings['view_name']);
      $classes[] = 'view--' . str_replace('_', '-', $settings['view_name'] . '--' . $settings['current_view_mode']);
    }

    // Blazy can still lazyload an unslick.
    if ($settings['lazy'] == 'blazy' || !empty($settings['blazy'])) {
      $attributes['class'][] = 'blazy';
      $attributes['data-blazy'] = empty($settings['blazy_data']) ? '' : drupal_json_encode($settings['blazy_data']);
    }

    // Provide a context for lightbox, or multimedia galleries, save for grid.
    if (!empty($settings['media_switch'])) {
      $switch = str_replace('_', '-', $settings['media_switch']);
      $classes[] = $switch;

      // Only if not using grid, output the gallery attribute.
      if (empty($settings['grid'])) {
        $attributes['data-' . $switch . '-gallery'] = TRUE;
      }
    }
  }
  elseif ($settings['display'] == 'thumbnail') {
    if ($settings['thumbnail_caption']) {
      $classes[] = 'has-caption';
    }
  }
  foreach ($classes as $class) {
    $attributes['class'][] = 'slick--' . $class;
  }
  return $attributes;
}