X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fentity_browser%2Fsrc%2FPlugin%2FEntityBrowser%2FFieldWidgetDisplay%2FRenderedEntity.php;fp=web%2Fmodules%2Fcontrib%2Fentity_browser%2Fsrc%2FPlugin%2FEntityBrowser%2FFieldWidgetDisplay%2FRenderedEntity.php;h=618b1bce830200433135518f0eaf4c75bb8566e9;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/modules/contrib/entity_browser/src/Plugin/EntityBrowser/FieldWidgetDisplay/RenderedEntity.php b/web/modules/contrib/entity_browser/src/Plugin/EntityBrowser/FieldWidgetDisplay/RenderedEntity.php new file mode 100644 index 000000000..618b1bce8 --- /dev/null +++ b/web/modules/contrib/entity_browser/src/Plugin/EntityBrowser/FieldWidgetDisplay/RenderedEntity.php @@ -0,0 +1,118 @@ +entityTypeManager = $entity_type_manager; + $this->entityDisplayRepository = $entity_display_repository; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('entity_type.manager'), + $container->get('entity_display.repository') + ); + } + + /** + * {@inheritdoc} + */ + public function view(EntityInterface $entity) { + return $this->entityTypeManager->getViewBuilder($this->configuration['entity_type'])->view($entity, $this->configuration['view_mode']); + } + + /** + * {@inheritdoc} + */ + public function settingsForm(array $form, FormStateInterface $form_state) { + $options = []; + foreach ($this->entityDisplayRepository->getViewModeOptions($this->configuration['entity_type']) as $id => $view_mode_label) { + $options[$id] = $view_mode_label; + } + + return [ + 'view_mode' => [ + '#type' => 'select', + '#title' => $this->t('View mode'), + '#description' => $this->t('Select view mode to be used when rendering entities.'), + '#default_value' => $this->configuration['view_mode'], + '#options' => $options, + ], + ]; + } + + /** + * {@inheritdoc} + */ + public function defaultConfiguration() { + return [ + 'view_mode' => 'default', + ] + parent::defaultConfiguration(); + } + + /** + * {@inheritdoc} + */ + public function calculateDependencies() { + $dependencies = parent::calculateDependencies(); + if ($view_mode = $this->entityTypeManager->getStorage('entity_view_mode')->load($this->configuration['entity_type'] . '.' . $this->configuration['view_mode'])) { + $dependencies[$view_mode->getConfigDependencyKey()][] = $view_mode->getConfigDependencyName(); + } + return $dependencies; + } + +}