SlickParagraphsFormatter.php in Slick Paragraphs 8
File
src/Plugin/Field/FieldFormatter/SlickParagraphsFormatter.php
View source
<?php
namespace Drupal\slick_paragraphs\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\slick_media\Plugin\Field\FieldFormatter\SlickMediaFormatter;
class SlickParagraphsFormatter extends SlickMediaFormatter {
public function getScopedFormElements() {
$admin = $this
->admin();
$target_type = $this
->getFieldSetting('target_type');
$views_ui = $this
->getFieldSetting('handler') == 'default';
$bundles = $views_ui ? [] : $this
->getFieldSetting('handler_settings')['target_bundles'];
$media = $admin
->getFieldOptions($bundles, [
'entity_reference',
], $target_type, 'media');
$stages = $admin
->getFieldOptions($bundles, [
'image',
'video_embed_field',
], $target_type);
return [
'images' => $stages,
'overlays' => $stages + $media,
] + parent::getScopedFormElements();
}
public static function isApplicable(FieldDefinitionInterface $field_definition) {
$storage = $field_definition
->getFieldStorageDefinition();
$paragraph = $storage
->getTargetEntityTypeId() === 'paragraph';
return $paragraph && $storage
->isMultiple() && $storage
->getSetting('target_type') === 'paragraph';
}
}