class SlickMediaFormatter in Slick Carousel 8.2
Plugin implementation of the 'slick media' formatter.
Plugin annotation
@FieldFormatter(
id = "slick_media",
label = @Translation("Slick Media"),
description = @Translation("Display the referenced entities as a Slick carousel."),
field_types = {
"entity_reference",
},
quickedit = {
"editor" = "disabled"
}
)
Hierarchy
- class \Drupal\slick\Plugin\Field\FieldFormatter\SlickEntityReferenceFormatterBase extends \Drupal\blazy\Dejavu\BlazyEntityReferenceBase implements ContainerFactoryPluginInterface uses SlickFormatterTrait
- class \Drupal\slick\Plugin\Field\FieldFormatter\SlickMediaFormatter uses SlickFormatterViewTrait
Expanded class hierarchy of SlickMediaFormatter
File
- src/
Plugin/ Field/ FieldFormatter/ SlickMediaFormatter.php, line 23
Namespace
Drupal\slick\Plugin\Field\FieldFormatterView source
class SlickMediaFormatter extends SlickEntityReferenceFormatterBase {
use SlickFormatterViewTrait;
/**
* Returns the blazy manager.
*/
public function blazyManager() {
return $this->formatter;
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$entities = $this
->getEntitiesToView($items, $langcode);
// Early opt-out if the field is empty.
if (empty($entities)) {
return [];
}
return $this
->commonViewElements($items, $langcode, $entities);
}
/**
* Builds the settings.
*
* @todo inherit and extends parent post blazy:2.x.
*/
public function buildSettings() {
return [
'blazy' => TRUE,
] + $this
->traitBuildSettings();
}
/**
* {@inheritdoc}
*/
public function getScopedFormElements() {
$multiple = $this->fieldDefinition
->getFieldStorageDefinition()
->isMultiple();
return [
'grid_form' => $multiple,
'style' => $multiple,
] + $this
->getCommonScopedFormElements() + parent::getScopedFormElements();
}
/**
* {@inheritdoc}
*/
public static function isApplicable(FieldDefinitionInterface $field_definition) {
$storage = $field_definition
->getFieldStorageDefinition();
return $storage
->isMultiple() && $storage
->getSetting('target_type') === 'media';
}
}