Skip to content

Commit

Permalink
add images to excerpt data
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes committed Dec 19, 2019
1 parent 5faa1c6 commit a9c2267
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Content/Application/ContentWorkflow/ContentWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ private function getWorkflow(): SymfonyWorkflowInterface
WorkflowInterface::WORKFLOW_PLACE_UNPUBLISHED
))
// Transfer to publish
->addTransition(new Transition(
WorkflowInterface::WORKFLOW_TRANSITION_PUBLISH,
WorkflowInterface::WORKFLOW_PLACE_PUBLISHED,
WorkflowInterface::WORKFLOW_PLACE_PUBLISHED
))
->addTransition(new Transition(
WorkflowInterface::WORKFLOW_TRANSITION_PUBLISH,
WorkflowInterface::WORKFLOW_PLACE_UNPUBLISHED,
Expand Down
22 changes: 21 additions & 1 deletion Content/Infrastructure/Sulu/Route/ContentDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ExcerptInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\SeoInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface;
use Sulu\Bundle\TagBundle\Tag\TagInterface;
use Sulu\Component\Content\Document\Behavior\ExtensionBehavior;

class ContentDocument implements ExtensionBehavior
Expand Down Expand Up @@ -61,12 +62,31 @@ public function getExtensionsData(): array

$excerpt = [];
if ($this->content instanceof ExcerptInterface) {
$image = $this->content->getExcerptImage();
$icon = $this->content->getExcerptIcon();

$excerpt = [
'title' => $this->content->getExcerptTitle(),
'description' => $this->content->getExcerptDescription(),
'more' => $this->content->getExcerptMore(),
'categories' => $this->content->getExcerptCategoryIds(),
'tags' => $this->content->getExcerptTags(),
'tags' => array_map(
function (TagInterface $tag) {
return $tag->getId();
},
$this->content->getExcerptTags()
),
'images' => [
'ids' => $image ? [
$image['id'],
] : [],
],
'icon' => [
'ids' => $icon ? [
$icon['id'],
] : [],
],
'audience_targeting_groups' => [],
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public function transitionProvider(): \Generator
'published' => [
'request_for_review' => false,
'reject' => false,
'publish' => false,
'publish' => true,
'unpublish' => true,
'create_draft' => true,
'remove_draft' => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Sulu\Bundle\ContentBundle\Content\Domain\Model\SeoInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface;
use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Route\ContentDocument;
use Sulu\Bundle\TagBundle\Tag\TagInterface;
use Sulu\Component\Content\Compat\StructureInterface;

class ContentDocumentTest extends TestCase
Expand Down Expand Up @@ -57,8 +58,18 @@ public function testGetExtensionsData(): void
$content->getExcerptTitle()->willReturn('Excerpt Title');
$content->getExcerptDescription()->willReturn('Excerpt Description');
$content->getExcerptMore()->willReturn('Excerpt More');
$content->getExcerptCategoryIds()->willReturn([]);
$content->getExcerptTags()->willReturn([]);
$content->getExcerptCategoryIds()->willReturn([4, 5, 6]);
$content->getExcerptImage()->willReturn(['id' => 42]);
$content->getExcerptIcon()->willReturn(['id' => 43]);

$tag1 = $this->prophesize(TagInterface::class);
$tag1->getId()->willReturn(1);
$tag2 = $this->prophesize(TagInterface::class);
$tag2->getId()->willReturn(2);
$tag3 = $this->prophesize(TagInterface::class);
$tag3->getId()->willReturn(3);

$content->getExcerptTags()->willReturn([$tag1->reveal(), $tag2->reveal(), $tag3->reveal()]);

$document = $this->createContentDocument($content->reveal());

Expand All @@ -77,8 +88,11 @@ public function testGetExtensionsData(): void
'title' => 'Excerpt Title',
'description' => 'Excerpt Description',
'more' => 'Excerpt More',
'categories' => [],
'tags' => [],
'categories' => [4, 5, 6],
'tags' => [1, 2, 3],
'images' => ['ids' => [42]],
'icon' => ['ids' => [43]],
'audience_targeting_groups' => [],
],
],
$document->getExtensionsData()
Expand Down

0 comments on commit a9c2267

Please sign in to comment.