Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add single article selection content type #2

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

namespace Sulu\Article\Infrastructure\Sulu\Content;

use Sulu\Article\Domain\Repository\ArticleRepositoryInterface;
use Sulu\Article\Infrastructure\Doctrine\Repository\ArticleRepository;
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;

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

$this->articleRepository = $articleRepository;
$this->referenceStore = $referenceStore;
}

public function getContentData(PropertyInterface $property)
{
$uuid = $property->getValue();
if (null === $uuid) {
return null;
}

$dimensionAttributes = [
'locale' => $property->getStructure()->getLanguageCode(),
'stage' => DimensionContentInterface::STAGE_DRAFT,
TheCadien marked this conversation as resolved.
Show resolved Hide resolved
];

return $this->articleRepository->getOneBy(
TheCadien marked this conversation as resolved.
Show resolved Hide resolved
filters: \array_merge(
[
'uuid' => $uuid,
'load_ghost_content' => true,
TheCadien marked this conversation as resolved.
Show resolved Hide resolved
],
$dimensionAttributes,
),
selects: [
ArticleRepositoryInterface::GROUP_SELECT_ARTICLE_ADMIN => true,
TheCadien marked this conversation as resolved.
Show resolved Hide resolved
]);
}

public function preResolve(PropertyInterface $property)
{
$uuid = $property->getValue();
if (null === $uuid) {
return;
}

$this->referenceStore->add($uuid);
}
}

43 changes: 26 additions & 17 deletions src/Infrastructure/Symfony/HttpKernel/SuluArticleBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Sulu\Article\Infrastructure\Sulu\Content\ArticleLinkProvider;
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 @@ -62,23 +63,23 @@ public function configure(DefinitionConfigurator $definition): void
{
$definition->rootNode()
->children()
->arrayNode('objects')
->addDefaultsIfNotSet()
->children()
->arrayNode('article')
->addDefaultsIfNotSet()
->children()
->scalarNode('model')->defaultValue(Article::class)->end()
->end()
->end()
->arrayNode('article_content')
->addDefaultsIfNotSet()
->children()
->scalarNode('model')->defaultValue(ArticleDimensionContent::class)->end()
->end()
->end()
->end()
->end()
->arrayNode('objects')
->addDefaultsIfNotSet()
->children()
->arrayNode('article')
->addDefaultsIfNotSet()
->children()
->scalarNode('model')->defaultValue(Article::class)->end()
->end()
->end()
->arrayNode('article_content')
->addDefaultsIfNotSet()
->children()
->scalarNode('model')->defaultValue(ArticleDimensionContent::class)->end()
->end()
->end()
->end()
->end()
->end();
}

Expand Down Expand Up @@ -245,6 +246,14 @@ 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.article_selection')
->class(SingleArticleSelectionContentType::class)
->args([
new Reference('sulu_article.article_repository'),
new Reference('sulu_article.article_reference_store')
])
->tag('sulu.content.type', ['alias' => 'single_article_selection']);

$services->set('sulu_article.article_data_provider')
->class(ContentDataProvider::class) // TODO this should not be handled via Content Bundle instead own service which uses the ArticleRepository
->args([
Expand Down