public function SlickViewsBase::buildElements in Slick Views 7.3
Same name and namespace in other branches
- 8.2 src/Plugin/views/style/SlickViewsBase.php \Drupal\slick_views\Plugin\views\style\SlickViewsBase::buildElements()
Returns slick contents.
2 calls to SlickViewsBase::buildElements()
- SlickGrouping::render_row_group 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 148
Class
- SlickViewsBase
- The base class common for Slick style plugins.
Namespace
Drupal\slick_views\Plugin\views\styleCode
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']['#item'])) {
$item = $thumbnail['rendered']['#item'];
// @todo re-check at D7.
$uri = is_object($item) ? $item->uri : $item['uri'];
$settings['thumbnail_style'] = $thumbnail['rendered']['#image_style'];
$settings['thumbnail_uri'] = image_style_path($settings['thumbnail_style'], $uri);
}
}
$slide['settings'] = $settings;
// Use Vanilla slick if so configured, ignoring Slick markups.
if (!empty($settings['vanilla'])) {
$slide[$item_id] = $view->style_plugin->row_plugin
->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'])) {
$class = $this
->getFieldString($row, $settings['class'], $index, TRUE);
// Ensures useless field name is overriden, even if empty.
$slide['settings']['class'] = empty($class) ? '' : $class;
}
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;
}