diff --git a/src/Infrastructure/Sulu/Content/SingleArticleSelectionContentType.php b/src/Infrastructure/Sulu/Content/SingleArticleSelectionContentType.php new file mode 100644 index 00000000..9ba0ea2d --- /dev/null +++ b/src/Infrastructure/Sulu/Content/SingleArticleSelectionContentType.php @@ -0,0 +1,72 @@ +articleRepository = $articleRepository; + $this->contentManager = $contentManager; + $this->referenceStore = $referenceStore; + } + + public function getContentData(PropertyInterface $property) + { + $uuid = $property->getValue(); + if (null === $uuid) { + return null; + } + + $dimensionAttributes = [ + 'locale' => $property->getStructure()->getLanguageCode(), + 'stage' => DimensionContentInterface::STAGE_LIVE, + ]; + + $article = $this->articleRepository->getOneBy( + filters: \array_merge( + [ + 'uuid' => $uuid, + ], + $dimensionAttributes, + ), + selects: [ + ArticleRepositoryInterface::GROUP_SELECT_ARTICLE_WEBSITE => true, + ]); + + + $dimensionContent = $this->contentManager->resolve($article, $dimensionAttributes); + return $this->contentManager->normalize($dimensionContent); + } + + public function preResolve(PropertyInterface $property) + { + $uuid = $property->getValue(); + if (null === $uuid) { + return; + } + + $this->referenceStore->add($uuid); + } +} + diff --git a/src/Infrastructure/Symfony/HttpKernel/SuluArticleBundle.php b/src/Infrastructure/Symfony/HttpKernel/SuluArticleBundle.php index 99486afc..a4534d71 100644 --- a/src/Infrastructure/Symfony/HttpKernel/SuluArticleBundle.php +++ b/src/Infrastructure/Symfony/HttpKernel/SuluArticleBundle.php @@ -22,6 +22,7 @@ use Sulu\Article\Infrastructure\Sulu\Content\ArticleSelectionContentType; use Sulu\Article\Infrastructure\Sulu\Content\ArticleSitemapProvider; use Sulu\Article\Infrastructure\Sulu\Content\ArticleTeaserProvider; +use Sulu\Article\Infrastructure\Sulu\Content\SingleArticleSelectionContentType; use Sulu\Article\UserInterface\Controller\Admin\ArticleController; use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Preview\ContentObjectProvider; use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Search\ContentSearchMetadataProvider; @@ -246,6 +247,15 @@ public function loadExtension(array $config, ContainerConfigurator $container, C ->class(ReferenceStore::class) ->tag('sulu_website.reference_store', ['alias' => ArticleInterface::RESOURCE_KEY]); + $services->set('sulu_article.content_types.single_article_selection') + ->class(SingleArticleSelectionContentType::class) + ->args([ + new Reference('sulu_article.article_repository'), + new Reference('sulu_content.content_manager'), + new Reference('sulu_article.article_reference_store') + ]) + ->tag('sulu.content.type', ['alias' => 'single_article_selection']); + $services->set('sulu_article.content_types.article_selection') ->class(ArticleSelectionContentType::class) ->args([