GridStackMediaFormatter.php in GridStack 8.2
File
src/Plugin/Field/FieldFormatter/GridStackMediaFormatter.php
View source
<?php
namespace Drupal\gridstack\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\blazy\Plugin\Field\FieldFormatter\BlazyMediaFormatterBase;
use Drupal\gridstack\GridStackDefault;
use Symfony\Component\DependencyInjection\ContainerInterface;
class GridStackMediaFormatter extends BlazyMediaFormatterBase {
use GridStackFormatterTrait;
use GridStackFormatterViewTrait;
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 static function defaultSettings() {
return GridStackDefault::extendedSettings() + parent::defaultSettings();
}
public function viewElements(FieldItemListInterface $items, $langcode) {
$entities = $this
->getEntitiesToView($items, $langcode);
if (empty($entities)) {
return [];
}
return $this
->commonViewElements($items, $langcode, $entities);
}
public function getScopedFormElements() {
return [
'vanilla' => TRUE,
'no_ratio' => TRUE,
'responsive_image' => TRUE,
] + $this
->getCommonScopedFormElements() + parent::getScopedFormElements();
}
public static function isApplicable(FieldDefinitionInterface $field_definition) {
$storage = $field_definition
->getFieldStorageDefinition();
return $storage
->isMultiple() && $storage
->getSetting('target_type') === 'media';
}
}