BlazyMediaFormatter.php in Blazy 8
File
src/Plugin/Field/FieldFormatter/BlazyMediaFormatter.php
View source
<?php
namespace Drupal\blazy\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\EntityReferenceFieldItemListInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
class BlazyMediaFormatter extends BlazyFormatter {
protected function getEntitiesToView(EntityReferenceFieldItemListInterface $items, $langcode) {
$media = parent::getEntitiesToView($items, $langcode);
$entities = [];
foreach ($media as $media_item) {
$entity = $media_item->thumbnail->entity;
$entity->_referringItem = $media_item->thumbnail;
$entities[] = $entity;
}
return $entities;
}
public static function isApplicable(FieldDefinitionInterface $field_definition) {
return $field_definition
->getFieldStorageDefinition()
->getSetting('target_type') == 'media';
}
}