You are here

public function SlickViewsBase::buildElements in Slick Views 8.2

Same name and namespace in other branches
  1. 7.3 src/Plugin/views/style/SlickViewsBase.php \Drupal\slick_views\Plugin\views\style\SlickViewsBase::buildElements()

Returns slick contents.

2 calls to SlickViewsBase::buildElements()
SlickGrouping::renderRowGroup in src/Plugin/views/style/SlickGrouping.php
Overrides StylePluginBase::renderRowGroup().
SlickViews::render in src/Plugin/views/style/SlickViews.php
Overrides StylePluginBase::render().

File

src/Plugin/views/style/SlickViewsBase.php, line 158

Class

SlickViewsBase
The base class common for Slick style plugins.

Namespace

Drupal\slick_views\Plugin\views\style

Code

public function buildElements(array $settings, $rows) {
  $build = [];
  $view = $this->view;
  $item_id = $settings['item_id'];
  foreach ($rows as $index => $row) {
    $view->row_index = $index;
    $slide = [];
    $thumb = $slide[$item_id] = [];

    // Provides a potential unique thumbnail different from the main image.
    if (!empty($settings['thumbnail'])) {
      $thumbnail = $this
        ->getFieldRenderable($row, 0, $settings['thumbnail']);
      if (isset($thumbnail['rendered']['#image_style'], $thumbnail['rendered']['#item']) && ($item = $thumbnail['rendered']['#item'])) {
        $uri = ($entity = $item->entity) && empty($item->uri) ? $entity
          ->getFileUri() : $item->uri;
        $settings['thumbnail_style'] = $thumbnail['rendered']['#image_style'];
        $settings['thumbnail_uri'] = empty($settings['thumbnail_style']) ? $uri : $this->manager
          ->entityLoad($settings['thumbnail_style'], 'image_style')
          ->buildUri($uri);
      }
    }
    $slide['settings'] = $settings;

    // Use Vanilla slick if so configured, ignoring Slick markups.
    if (!empty($settings['vanilla'])) {
      $slide[$item_id] = $view->rowPlugin
        ->render($row);
    }
    else {

      // Otherwise, extra works. With a working Views cache, no big deal.
      $this
        ->buildElement($slide, $row, $index);

      // Build thumbnail navs if so configured.
      if (!empty($settings['nav'])) {
        $thumb[$item_id] = empty($settings['thumbnail']) ? [] : $this
          ->getFieldRendered($index, $settings['thumbnail']);
        $thumb['caption'] = empty($settings['thumbnail_caption']) ? [] : $this
          ->getFieldRendered($index, $settings['thumbnail_caption']);
        $build['thumb']['items'][$index] = $thumb;
      }
    }
    if (!empty($settings['class'])) {
      $classes = $this
        ->getFieldString($row, $settings['class'], $index);
      $slide['settings']['class'] = empty($classes[$index]) ? [] : $classes[$index];
    }
    if (empty($slide[$item_id]) && !empty($settings['image'])) {
      $slide[$item_id] = $this
        ->getFieldRendered($index, $settings['image']);
    }
    $build['items'][$index] = $slide;
    unset($slide, $thumb);
  }
  unset($view->row_index);
  return $build;
}