public function SlickFileFormatterBase::buildElements in Slick Carousel 8.2
Same name and namespace in other branches
- 8 src/Plugin/Field/FieldFormatter/SlickFileFormatterBase.php \Drupal\slick\Plugin\Field\FieldFormatter\SlickFileFormatterBase::buildElements()
Build the slick carousel elements.
File
- src/
Plugin/ Field/ FieldFormatter/ SlickFileFormatterBase.php, line 51
Class
- SlickFileFormatterBase
- Base class for slick image and file ER formatters.
Namespace
Drupal\slick\Plugin\Field\FieldFormatterCode
public function buildElements(array &$build, $files) {
$settings =& $build['settings'];
$item_id = $settings['item_id'];
$tn_caption = empty($settings['thumbnail_caption']) ? NULL : $settings['thumbnail_caption'];
foreach ($files as $delta => $file) {
$settings['delta'] = $delta;
$settings['type'] = 'image';
/** @var Drupal\image\Plugin\Field\FieldType\ImageItem $item */
$item = $file->_referringItem;
$settings['file_tags'] = $file
->getCacheTags();
$settings['uri'] = $file
->getFileUri();
$element = [
'item' => $item,
'settings' => $settings,
];
// @todo remove, no longer file entity/VEF/M for pure Media.
$this
->buildElement($element, $file);
$settings = $element['settings'];
// Image with responsive image, lazyLoad, and lightbox supports.
$element[$item_id] = $this->formatter
->getBlazy($element);
if (!empty($settings['caption'])) {
foreach ($settings['caption'] as $caption) {
$element['caption'][$caption] = empty($element['item']->{$caption}) ? [] : [
'#markup' => Xss::filterAdmin($element['item']->{$caption}),
];
}
}
// Build individual slick item.
$build['items'][$delta] = $element;
// Build individual slick thumbnail.
if (!empty($settings['nav'])) {
$thumb = [
'settings' => $settings,
];
// Thumbnail usages: asNavFor pagers, dot, arrows, photobox thumbnails.
$thumb[$item_id] = empty($settings['thumbnail_style']) ? [] : $this->formatter
->getThumbnail($settings, $element['item']);
$thumb['caption'] = empty($element['item']->{$tn_caption}) ? [] : [
'#markup' => Xss::filterAdmin($element['item']->{$tn_caption}),
];
$build['thumb']['items'][$delta] = $thumb;
unset($thumb);
}
unset($element);
}
}