Skip to content

Commit

Permalink
Add single article selection content type (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCadien authored and alexander-schranz committed Aug 8, 2024
1 parent 2a4a733 commit 8ef7839
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"doctrine/collections": "^1.0",
"doctrine/orm": "^2.5.3",
"doctrine/doctrine-bundle": "^1.10 || ^2.0",
"doctrine/persistence": "^1.3 || ^2.0",
"doctrine/persistence": "^1.3 || ^2.0 || ^3.0",
"jms/serializer": "^3.3",
"jms/serializer-bundle": "^3.3 || ^4.0 || ^5.0",
"ramsey/uuid": "^3.1 || ^4.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);

namespace Sulu\Article\Infrastructure\Sulu\Content;

use Sulu\Article\Domain\Repository\ArticleRepositoryInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ContentManager\ContentManagerInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
use Sulu\Bundle\WebsiteBundle\ReferenceStore\ReferenceStoreInterface;
use Sulu\Component\Content\Compat\PropertyInterface;
use Sulu\Component\Content\PreResolvableContentTypeInterface;
use Sulu\Component\Content\SimpleContentType;

class SingleArticleSelectionContentType extends SimpleContentType implements PreResolvableContentTypeInterface
{
private ArticleRepositoryInterface $articleRepository;

private ContentManagerInterface $contentManager;

public function __construct(
ArticleRepositoryInterface $articleRepository,
ContentManagerInterface $contentManager,
ReferenceStoreInterface $referenceStore,
)
{
parent::__construct('Article');

$this->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);
}
}

17 changes: 10 additions & 7 deletions src/Infrastructure/Symfony/HttpKernel/SuluArticleBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,13 +50,6 @@ final class SuluArticleBundle extends AbstractBundle
use PersistenceExtensionTrait;
use PersistenceBundleTrait;

public const ALIAS = 'sulu_next_article';
public const NAME = 'SuluNextArticleBundle';

protected string $extensionAlias = self::ALIAS;

protected $name = self::NAME;

/**
* @internal this method is not part of the public API and should only be called by the Symfony framework classes
*/
Expand Down Expand Up @@ -246,6 +240,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([
Expand Down

0 comments on commit 8ef7839

Please sign in to comment.