forked from sulu/SuluArticleBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add single article selection content type (#2)
- Loading branch information
1 parent
2a4a733
commit 8ef7839
Showing
3 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/Infrastructure/Sulu/Content/SingleArticleSelectionContentType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters