SlickFileFormatter.php in Slick Carousel 8.2
File
src/Plugin/Field/FieldFormatter/SlickFileFormatter.php
View source
<?php
namespace Drupal\slick\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\blazy\Dejavu\BlazyVideoTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SlickFileFormatter extends SlickFileFormatterBase {
use BlazyVideoTrait;
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
return self::injectServices($instance, $container, 'entity');
}
public function buildElement(array &$build, $entity) {
$settings = $build['settings'];
$data = [];
if (empty($build['item'])) {
if (method_exists($this->blazyOembed, 'getImageItem')) {
$data = $this->blazyOembed
->getImageItem($entity);
}
elseif (method_exists($this, 'getImageItem')) {
$data = $this
->getImageItem($entity);
}
if ($data) {
$build['item'] = $data['item'];
$build['settings'] = array_merge($settings, $data['settings']);
}
}
$this->blazyOembed
->getMediaItem($build, $entity);
}
public function buildSettings() {
return [
'blazy' => TRUE,
] + parent::getSettings();
}
public function getScopedFormElements() {
return [
'fieldable_form' => TRUE,
'multimedia' => TRUE,
'view_mode' => $this->viewMode,
] + $this
->getCommonScopedFormElements() + parent::getScopedFormElements();
}
public static function isApplicable(FieldDefinitionInterface $field_definition) {
$storage = $field_definition
->getFieldStorageDefinition();
return $storage
->isMultiple() && $storage
->getSetting('target_type') === 'file';
}
}
Classes
Name |
Description |
SlickFileFormatter |
Plugin implementation of the 'Slick File' formatter to get ME within images. |