SlickFormatter.php in Slick Carousel 8.2
File
src/SlickFormatter.php
View source
<?php
namespace Drupal\slick;
use Drupal\slick\Entity\Slick;
use Drupal\blazy\BlazyFormatter;
use Drupal\image\Plugin\Field\FieldType\ImageItem;
class SlickFormatter extends BlazyFormatter implements SlickFormatterInterface {
public function buildSettings(array &$build, $items) {
$settings =& $build['settings'];
$settings['item_id'] = 'slide';
$settings['namespace'] = 'slick';
$settings['_unload'] = FALSE;
parent::buildSettings($build, $items);
}
public function preBuildElements(array &$build, $items, array $entities = []) {
parent::preBuildElements($build, $items, $entities);
$settings =& $build['settings'];
$build['optionset'] = Slick::loadWithFallback($settings['optionset']);
if (!isset($settings['nav'])) {
$settings['nav'] = !empty($settings['optionset_thumbnail']) && isset($items[1]);
}
if (empty($settings['vanilla'])) {
$build['optionset']
->whichLazy($settings);
}
else {
$settings['nav'] = FALSE;
}
if (empty($settings['override']) && isset($settings['overridables'])) {
$settings['overridables'] = array_filter($settings['overridables']);
}
$this
->getModuleHandler()
->alter('slick_settings', $build, $items);
}
public function getThumbnail(array $settings = [], $item = NULL) {
if (!empty($settings['uri'])) {
return [
'#theme' => 'image_style',
'#style_name' => empty($settings['thumbnail_style']) ? 'thumbnail' : $settings['thumbnail_style'],
'#uri' => $settings['uri'],
'#item' => $item,
'#alt' => $item && $item instanceof ImageItem ? $item
->getValue()['alt'] : '',
];
}
return [];
}
}