public function SlickViews::buildElements in Slick Views 8
Returns slick contents.
1 call to SlickViews::buildElements()
- SlickViews::render in src/
Plugin/ views/ style/ SlickViews.php - Overrides StylePluginBase::render().
File
- src/
Plugin/ views/ style/ SlickViews.php, line 157
Class
- SlickViews
- Slick style plugin.
Namespace
Drupal\slick_views\Plugin\views\styleCode
public function buildElements(array $settings, $rows) {
$build = [];
$view = $this->view;
$keys = array_keys($view->field);
$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']['#item'])) {
$item = $thumbnail['rendered']['#item'];
$settings['thumbnail_uri'] = ($entity = $item->entity) && empty($item->uri) ? $entity
->getFileUri() : $item->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])) {
$slide[$item_id] = $this
->getFieldRendered($index, $settings['image']);
}
$build['items'][$index] = $slide;
unset($slide, $thumb);
}
unset($view->row_index);
return $build;
}