SlickFormatterBase.php in Slick Carousel 7.3
File
src/Plugin/Field/FieldFormatter/SlickFormatterBase.php
View source
<?php
namespace Drupal\slick\Plugin\Field\FieldFormatter;
use Drupal\blazy\Plugin\Field\FieldFormatter\BlazyFormatterBase;
use Drupal\slick\SlickDefault;
use Drupal\slick\SlickFormatterInterface;
use Drupal\slick\SlickManagerInterface;
abstract class SlickFormatterBase extends BlazyFormatterBase {
public function __construct($plugin_id, $field, $instance, SlickFormatterInterface $formatter, SlickManagerInterface $manager) {
parent::__construct($plugin_id, $field, $instance);
$this->formatter = $formatter;
$this->manager = $manager;
}
public static function defaultSettings() {
return SlickDefault::imageSettings();
}
public function buildElements(array &$build, $items) {
$settings = $build['settings'];
$item_id = $settings['item_id'];
foreach ($items as $delta => $item) {
$settings['delta'] = $delta;
$settings['type'] = isset($item->type) ? $item->type : 'image';
$settings['uri'] = $item->uri;
$element = [
'item' => $item,
'settings' => $settings,
'content' => [],
];
$this
->buildElement($element, $item, $delta);
$build['items'][$delta] = $element;
if (!empty($settings['nav'])) {
$thumb = [
'settings' => $element['settings'],
];
$thumb[$item_id] = empty($settings['thumbnail_style']) ? [] : $this
->formatter()
->getThumbnail($element['settings'], $element['item']);
$thumb['caption'] = empty($settings['thumbnail_caption']) ? [] : array_filter($this
->getCaption($item, $settings['thumbnail_caption'], $settings));
$build['thumb']['items'][$delta] = $thumb;
}
}
}
protected abstract function getCaption($entity, $field_name, $settings);
public function getScopedFormElements() {
return [
'namespace' => 'slick',
'nav' => TRUE,
'thumb_captions' => [
'title' => t('Title'),
'alt' => t('Alt'),
],
'thumb_positions' => TRUE,
] + parent::getScopedFormElements();
}
}