SlickFormatter.php in Slick Carousel 8
File
src/SlickFormatter.php
View source
<?php
namespace Drupal\slick;
use Drupal\slick\Entity\Slick;
use Drupal\blazy\BlazyFormatterManager;
use Drupal\image\Plugin\Field\FieldType\ImageItem;
class SlickFormatter extends BlazyFormatterManager implements SlickFormatterInterface {
public function buildSettings(array &$build, $items) {
$settings =& $build['settings'];
$settings['item_id'] = 'slide';
$settings['namespace'] = 'slick';
parent::buildSettings($build, $items);
$build['optionset'] = Slick::load($settings['optionset']);
if (empty($build['optionset'])) {
$build['optionset'] = Slick::load('default');
}
if (!isset($settings['nav'])) {
$settings['nav'] = !empty($settings['optionset_thumbnail']) && isset($items[1]);
}
if (empty($settings['vanilla'])) {
$lazy = $build['optionset']
->getSetting('lazyLoad');
$settings['blazy'] = $lazy == 'blazy' || !empty($settings['blazy']);
$settings['lazy'] = $settings['blazy'] ? 'blazy' : $lazy;
if (empty($settings['blazy'])) {
$settings['lazy_class'] = $settings['lazy_attribute'] = 'lazy';
}
}
else {
$settings['nav'] = FALSE;
}
if (empty($settings['override']) && isset($settings['overridables'])) {
$settings['overridables'] = array_filter($settings['overridables']);
}
}
public function getThumbnail(array $settings = [], $item = NULL) {
$thumbnail = [];
$thumbnail_alt = '';
if ($item instanceof ImageItem) {
$thumbnail_alt = $item
->getValue()['alt'];
}
if (!empty($settings['uri'])) {
$thumbnail = [
'#theme' => 'image_style',
'#style_name' => isset($settings['thumbnail_style']) ? $settings['thumbnail_style'] : 'thumbnail',
'#uri' => $settings['uri'],
'#item' => $item,
'#alt' => $thumbnail_alt,
];
}
return $thumbnail;
}
}