Skip to content

Commit

Permalink
Add constants for keys of ContentWorkflow transition context (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasnatter authored May 19, 2020
1 parent 225f969 commit 3b40e7b
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 36 deletions.
6 changes: 3 additions & 3 deletions Content/Application/ContentWorkflow/ContentWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ public function apply(

try {
$workflow->apply($localizedDimensionContent, $transitionName, [
'contentRichEntity' => $contentRichEntity,
'dimensionContentCollection' => $dimensionContentCollection,
'dimensionAttributes' => $dimensionAttributes,
ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity,
ContentWorkflowInterface::DIMENSION_CONTENT_COLLECTION_CONTEXT_KEY => $dimensionContentCollection,
ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes,
]);
} catch (UndefinedTransitionException $e) {
throw new UnknownContentTransitionException($e->getMessage(), $e->getCode(), $e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

interface ContentWorkflowInterface
{
const CONTENT_RICH_ENTITY_CONTEXT_KEY = 'contentRichEntity';
const DIMENSION_CONTENT_COLLECTION_CONTEXT_KEY = 'dimensionContentCollection';
const DIMENSION_ATTRIBUTES_CONTEXT_KEY = 'dimensionAttributes';

/**
* @param mixed[] $dimensionAttributes
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\Subscriber;

use Sulu\Bundle\ContentBundle\Content\Application\ContentCopier\ContentCopierInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\ContentWorkflowInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
Expand Down Expand Up @@ -50,9 +51,9 @@ public function onPublish(TransitionEvent $transitionEvent): void

$context = $transitionEvent->getContext();

$dimensionContentCollection = $context['dimensionContentCollection'] ?? null;
$dimensionAttributes = $context['dimensionAttributes'] ?? null;
$contentRichEntity = $context['contentRichEntity'] ?? null;
$dimensionContentCollection = $context[ContentWorkflowInterface::DIMENSION_CONTENT_COLLECTION_CONTEXT_KEY] ?? null;
$dimensionAttributes = $context[ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY] ?? null;
$contentRichEntity = $context[ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY] ?? null;

if (!$dimensionAttributes) {
throw new \RuntimeException('No "dimensionAttributes" given.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\Subscriber;

use Sulu\Bundle\ContentBundle\Content\Application\ContentCopier\ContentCopierInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\ContentWorkflowInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionInterface;
Expand Down Expand Up @@ -41,12 +42,12 @@ public function onRemoveDraft(TransitionEvent $transitionEvent): void

$context = $transitionEvent->getContext();

$dimensionAttributes = $context['dimensionAttributes'] ?? null;
$dimensionAttributes = $context[ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY] ?? null;
if (!$dimensionAttributes) {
throw new \RuntimeException('Transition context must contain "dimensionAttributes".');
}

$contentRichEntity = $context['contentRichEntity'] ?? null;
$contentRichEntity = $context[ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY] ?? null;
if (!$contentRichEntity instanceof ContentRichEntityInterface) {
throw new \RuntimeException('Transition context must contain "contentRichEntity".');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\Subscriber;

use Doctrine\ORM\EntityManagerInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\ContentWorkflowInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Exception\ContentNotFoundException;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
Expand Down Expand Up @@ -65,12 +66,12 @@ public function onUnpublish(TransitionEvent $transitionEvent): void

$context = $transitionEvent->getContext();

$dimensionAttributes = $context['dimensionAttributes'] ?? null;
$dimensionAttributes = $context[ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY] ?? null;
if (!$dimensionAttributes) {
throw new \RuntimeException('Transition context must contain "dimensionAttributes".');
}

$contentRichEntity = $context['contentRichEntity'] ?? null;
$contentRichEntity = $context[ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY] ?? null;
if (!$contentRichEntity instanceof ContentRichEntityInterface) {
throw new \RuntimeException('Transition context must contain "contentRichEntity".');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Doctrine\ORM\NoResultException;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\ContentWorkflowInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionInterface;
use Sulu\Bundle\RouteBundle\Model\RouteInterface;
use Sulu\Bundle\WebsiteBundle\Sitemap\Sitemap;
Expand All @@ -31,7 +32,7 @@
class ContentSitemapProvider implements SitemapProviderInterface
{
const ROUTE_ALIAS = 'route';
const CONTENT_RICH_ENTITY_ALIAS = 'contentRichEntity';
const CONTENT_RICH_ENTITY_ALIAS = ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY;
const LOCALIZED_DIMENSION_CONTENT_ALIAS = 'localizedDimensionContent';
const LOCALIZED_DIMENSION_ALIAS = 'localizedDimension';

Expand Down
3 changes: 2 additions & 1 deletion Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Doctrine\ORM\EntityManagerInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ContentManager\ContentManagerInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\ContentWorkflowInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Exception\ContentNotFoundException;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
Expand All @@ -27,7 +28,7 @@

abstract class ContentTeaserProvider implements TeaserProviderInterface
{
const CONTENT_RICH_ENTITY_ALIAS = 'contentRichEntity';
const CONTENT_RICH_ENTITY_ALIAS = ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY;

/**
* @var ContentManagerInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Sulu\Bundle\ContentBundle\Content\Application\ContentCopier\ContentCopierInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\ContentWorkflowInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\Subscriber\PublishTransitionSubscriber;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface;
Expand Down Expand Up @@ -72,8 +73,8 @@ public function testOnPublishNoDimensionContentCollection(): void
new Marking()
);
$event->setContext([
'dimensionAttributes' => $dimensionAttributes,
'contentRichEntity' => $contentRichEntity->reveal(),
ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes,
ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity->reveal(),
]);

$contentCopier = $this->prophesize(ContentCopierInterface::class);
Expand All @@ -99,8 +100,8 @@ public function testOnPublishNoContentRichEntity(): void
new Marking()
);
$event->setContext([
'dimensionAttributes' => $dimensionAttributes,
'dimensionContentCollection' => $dimensionContentCollection->reveal(),
ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes,
ContentWorkflowInterface::DIMENSION_CONTENT_COLLECTION_CONTEXT_KEY => $dimensionContentCollection->reveal(),
]);

$contentCopier = $this->prophesize(ContentCopierInterface::class);
Expand All @@ -126,8 +127,8 @@ public function testOnPublishNoDimensionAttributes(): void
new Marking()
);
$event->setContext([
'dimensionContentCollection' => $dimensionContentCollection->reveal(),
'contentRichEntity' => $contentRichEntity->reveal(),
ContentWorkflowInterface::DIMENSION_CONTENT_COLLECTION_CONTEXT_KEY => $dimensionContentCollection->reveal(),
ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity->reveal(),
]);

$contentCopier = $this->prophesize(ContentCopierInterface::class);
Expand Down Expand Up @@ -155,9 +156,9 @@ public function testOnPublish(): void
new Marking()
);
$event->setContext([
'dimensionContentCollection' => $dimensionContentCollection->reveal(),
'dimensionAttributes' => $dimensionAttributes,
'contentRichEntity' => $contentRichEntity->reveal(),
ContentWorkflowInterface::DIMENSION_CONTENT_COLLECTION_CONTEXT_KEY => $dimensionContentCollection->reveal(),
ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes,
ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity->reveal(),
]);

$contentCopier = $this->prophesize(ContentCopierInterface::class);
Expand Down Expand Up @@ -194,9 +195,9 @@ public function testOnPublishExistingPublished(): void
new Marking()
);
$event->setContext([
'dimensionContentCollection' => $dimensionContentCollection->reveal(),
'dimensionAttributes' => $dimensionAttributes,
'contentRichEntity' => $contentRichEntity->reveal(),
ContentWorkflowInterface::DIMENSION_CONTENT_COLLECTION_CONTEXT_KEY => $dimensionContentCollection->reveal(),
ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes,
ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity->reveal(),
]);

$contentCopier = $this->prophesize(ContentCopierInterface::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Sulu\Bundle\ContentBundle\Content\Application\ContentCopier\ContentCopierInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\ContentWorkflowInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\Subscriber\RemoveDraftTransitionSubscriber;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
Expand Down Expand Up @@ -70,7 +71,7 @@ public function testOnRemoveDraftNoDimensionAttributes(): void
new Marking()
);
$event->setContext([
'contentRichEntity' => $contentRichEntity->reveal(),
ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity->reveal(),
]);

$contentCopier = $this->prophesize(ContentCopierInterface::class);
Expand All @@ -94,7 +95,7 @@ public function testOnRemoveDraftNoContentRichEntity(): void
new Marking()
);
$event->setContext([
'dimensionAttributes' => $dimensionAttributes,
ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes,
]);

$contentCopier = $this->prophesize(ContentCopierInterface::class);
Expand All @@ -116,8 +117,8 @@ public function testOnRemoveDraft(): void
new Marking()
);
$event->setContext([
'dimensionAttributes' => $dimensionAttributes,
'contentRichEntity' => $contentRichEntity->reveal(),
ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes,
ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity->reveal(),
]);

$contentCopier = $this->prophesize(ContentCopierInterface::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\ContentWorkflowInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\Subscriber\UnpublishTransitionSubscriber;
use Sulu\Bundle\ContentBundle\Content\Domain\Exception\ContentNotFoundException;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
Expand Down Expand Up @@ -91,7 +92,7 @@ public function testOnUnpublishNoDimensionAttributes(): void
new Marking()
);
$event->setContext([
'contentRichEntity' => $contentRichEntity->reveal(),
ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity->reveal(),
]);

$dimensionRepository = $this->prophesize(DimensionRepositoryInterface::class);
Expand Down Expand Up @@ -122,7 +123,7 @@ public function testOnUnpublishNoContentRichEntity(): void
new Marking()
);
$event->setContext([
'dimensionAttributes' => $dimensionAttributes,
ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes,
]);

$dimensionRepository = $this->prophesize(DimensionRepositoryInterface::class);
Expand Down Expand Up @@ -153,8 +154,8 @@ public function testOnUnpublishEmptyDimensionCollection(): void
new Marking()
);
$event->setContext([
'dimensionAttributes' => $dimensionAttributes,
'contentRichEntity' => $contentRichEntity->reveal(),
ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes,
ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity->reveal(),
]);

$dimensionRepository = $this->prophesize(DimensionRepositoryInterface::class);
Expand Down Expand Up @@ -192,8 +193,8 @@ public function testOnUnpublishNoLocalizedDimensionContent(): void
new Marking()
);
$event->setContext([
'dimensionAttributes' => $dimensionAttributes,
'contentRichEntity' => $contentRichEntity->reveal(),
ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes,
ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity->reveal(),
]);

$dimensionRepository = $this->prophesize(DimensionRepositoryInterface::class);
Expand Down Expand Up @@ -241,8 +242,8 @@ public function testOnUnpublish(): void
new Marking()
);
$event->setContext([
'dimensionAttributes' => $dimensionAttributes,
'contentRichEntity' => $contentRichEntity->reveal(),
ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes,
ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity->reveal(),
]);

$dimensionRepository = $this->prophesize(DimensionRepositoryInterface::class);
Expand Down

0 comments on commit 3b40e7b

Please sign in to comment.