diff --git a/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapper.php b/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapper.php index 594456bd..b14dca25 100644 --- a/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapper.php +++ b/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapper.php @@ -16,6 +16,7 @@ use Sulu\Bundle\ContentBundle\Content\Domain\Factory\ContactFactoryInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\AuthorInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; class AuthorDataMapper implements DataMapperInterface { @@ -31,29 +32,14 @@ public function __construct(ContactFactoryInterface $contactFactory) public function map( array $data, - DimensionContentCollectionInterface $dimensionContentCollection + DimensionContentInterface $unlocalizedDimensionContent, + DimensionContentInterface $localizedDimensionContent ): void { - $dimensionAttributes = $dimensionContentCollection->getDimensionAttributes(); - $unlocalizedDimensionAttributes = \array_merge($dimensionAttributes, ['locale' => null]); - $unlocalizedObject = $dimensionContentCollection->getDimensionContent($unlocalizedDimensionAttributes); - - if (!$unlocalizedObject instanceof AuthorInterface) { - return; - } - - $localizedObject = $dimensionContentCollection->getDimensionContent($dimensionAttributes); - - if ($localizedObject) { - if (!$localizedObject instanceof AuthorInterface) { - throw new \RuntimeException(\sprintf('Expected "$localizedObject" from type "%s" but "%s" given.', AuthorInterface::class, \get_class($localizedObject))); - } - - $this->setAuthorData($localizedObject, $data); - + if (!$localizedDimensionContent instanceof AuthorInterface) { return; } - $this->setAuthorData($unlocalizedObject, $data); + $this->setAuthorData($localizedDimensionContent, $data); } /** diff --git a/Content/Application/ContentDataMapper/DataMapper/DataMapperInterface.php b/Content/Application/ContentDataMapper/DataMapper/DataMapperInterface.php index 0b732abc..b888b12f 100644 --- a/Content/Application/ContentDataMapper/DataMapper/DataMapperInterface.php +++ b/Content/Application/ContentDataMapper/DataMapper/DataMapperInterface.php @@ -13,7 +13,7 @@ namespace Sulu\Bundle\ContentBundle\Content\Application\ContentDataMapper\DataMapper; -use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; interface DataMapperInterface { @@ -22,6 +22,7 @@ interface DataMapperInterface */ public function map( array $data, - DimensionContentCollectionInterface $dimensionContentCollection + DimensionContentInterface $unlocalizedDimensionContent, + DimensionContentInterface $localizedDimensionContent ): void; } diff --git a/Content/Application/ContentDataMapper/DataMapper/ExcerptDataMapper.php b/Content/Application/ContentDataMapper/DataMapper/ExcerptDataMapper.php index ea6d52eb..3e5e7875 100644 --- a/Content/Application/ContentDataMapper/DataMapper/ExcerptDataMapper.php +++ b/Content/Application/ContentDataMapper/DataMapper/ExcerptDataMapper.php @@ -16,6 +16,7 @@ use Sulu\Bundle\ContentBundle\Content\Domain\Factory\CategoryFactoryInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Factory\TagFactoryInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ExcerptInterface; class ExcerptDataMapper implements DataMapperInterface @@ -38,29 +39,14 @@ public function __construct(TagFactoryInterface $tagFactory, CategoryFactoryInte public function map( array $data, - DimensionContentCollectionInterface $dimensionContentCollection + DimensionContentInterface $unlocalizedDimensionContent, + DimensionContentInterface $localizedDimensionContent ): void { - $dimensionAttributes = $dimensionContentCollection->getDimensionAttributes(); - $unlocalizedDimensionAttributes = \array_merge($dimensionAttributes, ['locale' => null]); - $unlocalizedObject = $dimensionContentCollection->getDimensionContent($unlocalizedDimensionAttributes); - - if (!$unlocalizedObject instanceof ExcerptInterface) { - return; - } - - $localizedObject = $dimensionContentCollection->getDimensionContent($dimensionAttributes); - - if ($localizedObject) { - if (!$localizedObject instanceof ExcerptInterface) { - throw new \RuntimeException(\sprintf('Expected "$localizedObject" from type "%s" but "%s" given.', ExcerptInterface::class, \get_class($localizedObject))); - } - - $this->setExcerptData($localizedObject, $data); - + if (!$localizedDimensionContent instanceof ExcerptInterface) { return; } - $this->setExcerptData($unlocalizedObject, $data); + $this->setExcerptData($localizedDimensionContent, $data); } /** diff --git a/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapper.php b/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapper.php index db36c749..15750d51 100644 --- a/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapper.php +++ b/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapper.php @@ -13,7 +13,7 @@ namespace Sulu\Bundle\ContentBundle\Content\Application\ContentDataMapper\DataMapper; -use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\RoutableInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface; use Sulu\Bundle\RouteBundle\Generator\RouteGeneratorInterface; @@ -77,23 +77,18 @@ public function __construct( public function map( array $data, - DimensionContentCollectionInterface $dimensionContentCollection + DimensionContentInterface $unlocalizedDimensionContent, + DimensionContentInterface $localizedDimensionContent ): void { - $dimensionAttributes = $dimensionContentCollection->getDimensionAttributes(); - $localizedObject = $dimensionContentCollection->getDimensionContent($dimensionAttributes); - - $unlocalizedDimensionAttributes = \array_merge($dimensionAttributes, ['locale' => null]); - $unlocalizedObject = $dimensionContentCollection->getDimensionContent($unlocalizedDimensionAttributes); - - if (!$localizedObject || !$localizedObject instanceof RoutableInterface) { + if (!$localizedDimensionContent instanceof RoutableInterface) { return; } - if (!$localizedObject instanceof TemplateInterface) { - throw new \RuntimeException('LocalizedObject needs to extend the TemplateInterface'); + if (!$localizedDimensionContent instanceof TemplateInterface) { + throw new \RuntimeException('LocalizedDimensionContent needs to extend the TemplateInterface'); } - $type = $localizedObject::getTemplateType(); + $type = $localizedDimensionContent::getTemplateType(); /** @var string|null $template */ $template = $data['template'] ?? null; @@ -116,13 +111,13 @@ public function map( return; } - if (!$localizedObject->getResourceId()) { + if (!$localizedDimensionContent->getResourceId()) { // FIXME the code only works if the entity is flushed once and has a valid id return; } - $locale = $localizedObject->getLocale(); + $locale = $localizedDimensionContent->getLocale(); if (!$locale) { return; } @@ -130,14 +125,14 @@ public function map( /** @var string $name */ $name = $property->getName(); - $currentRoutePath = $localizedObject->getTemplateData()[$name] ?? null; + $currentRoutePath = $localizedDimensionContent->getTemplateData()[$name] ?? null; if (!\array_key_exists($name, $data) && null !== $currentRoutePath) { return; } $entityClass = null; $routeSchema = null; - $resourceKey = $localizedObject::getResourceKey(); + $resourceKey = $localizedDimensionContent::getResourceKey(); foreach ($this->routeMappings as $key => $mapping) { if ($resourceKey === $mapping['resource_key']) { $entityClass = $mapping['entityClass'] ?? $key; @@ -157,8 +152,8 @@ public function map( $routeGenerationData = \array_merge( $data, [ - '_unlocalizedObject' => $unlocalizedObject, - '_localizedObject' => $localizedObject, + '_unlocalizedObject' => $unlocalizedDimensionContent, + '_localizedObject' => $localizedDimensionContent, ] ); @@ -174,7 +169,7 @@ public function map( $route = $this->routeManager->createOrUpdateByAttributes( $entityClass, - (string) $localizedObject->getResourceId(), + (string) $localizedDimensionContent->getResourceId(), $locale, $routePath ); @@ -182,9 +177,9 @@ public function map( $this->conflictResolver->resolve($route); if (($data[$name] ?? null) !== $route->getPath()) { - $localizedObject->setTemplateData( + $localizedDimensionContent->setTemplateData( \array_merge( - $localizedObject->getTemplateData(), + $localizedDimensionContent->getTemplateData(), [$name => $route->getPath()] ) ); diff --git a/Content/Application/ContentDataMapper/DataMapper/SeoDataMapper.php b/Content/Application/ContentDataMapper/DataMapper/SeoDataMapper.php index 53a2165f..0f85d769 100644 --- a/Content/Application/ContentDataMapper/DataMapper/SeoDataMapper.php +++ b/Content/Application/ContentDataMapper/DataMapper/SeoDataMapper.php @@ -14,35 +14,21 @@ namespace Sulu\Bundle\ContentBundle\Content\Application\ContentDataMapper\DataMapper; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\SeoInterface; class SeoDataMapper implements DataMapperInterface { public function map( array $data, - DimensionContentCollectionInterface $dimensionContentCollection + DimensionContentInterface $unlocalizedDimensionContent, + DimensionContentInterface $localizedDimensionContent ): void { - $dimensionAttributes = $dimensionContentCollection->getDimensionAttributes(); - $unlocalizedDimensionAttributes = \array_merge($dimensionAttributes, ['locale' => null]); - $unlocalizedObject = $dimensionContentCollection->getDimensionContent($unlocalizedDimensionAttributes); - - if (!$unlocalizedObject instanceof SeoInterface) { - return; - } - - $localizedObject = $dimensionContentCollection->getDimensionContent($dimensionAttributes); - - if ($localizedObject) { - if (!$localizedObject instanceof SeoInterface) { - throw new \RuntimeException(\sprintf('Expected "$localizedObject" from type "%s" but "%s" given.', SeoInterface::class, \get_class($localizedObject))); - } - - $this->setSeoData($localizedObject, $data); - + if (!$localizedDimensionContent instanceof SeoInterface) { return; - } + }Content/Application/ContentDataMapper/DataMapper/TemplateDataMapper.php - $this->setSeoData($unlocalizedObject, $data); + $this->setSeoData($localizedDimensionContent, $data); } /** diff --git a/Content/Application/ContentDataMapper/DataMapper/TemplateDataMapper.php b/Content/Application/ContentDataMapper/DataMapper/TemplateDataMapper.php index 040b3e11..dca56ddb 100644 --- a/Content/Application/ContentDataMapper/DataMapper/TemplateDataMapper.php +++ b/Content/Application/ContentDataMapper/DataMapper/TemplateDataMapper.php @@ -14,6 +14,7 @@ namespace Sulu\Bundle\ContentBundle\Content\Application\ContentDataMapper\DataMapper; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface; use Sulu\Component\Content\Metadata\Factory\StructureMetadataFactoryInterface; @@ -40,17 +41,16 @@ public function __construct(StructureMetadataFactoryInterface $factory, array $s public function map( array $data, - DimensionContentCollectionInterface $dimensionContentCollection + DimensionContentInterface $unlocalizedDimensionContent, + DimensionContentInterface $localizedDimensionContent ): void { - $dimensionAttributes = $dimensionContentCollection->getDimensionAttributes(); - $unlocalizedDimensionAttributes = \array_merge($dimensionAttributes, ['locale' => null]); - $unlocalizedObject = $dimensionContentCollection->getDimensionContent($unlocalizedDimensionAttributes); - - if (!$unlocalizedObject instanceof TemplateInterface) { + if (!$localizedDimensionContent instanceof TemplateInterface + || $unlocalizedDimensionContent instanceof TemplateInterface + ) { return; } - $type = $unlocalizedObject::getTemplateType(); + $type = $localizedDimensionContent::getTemplateType(); /** @var string|null $template */ $template = $data['template'] ?? null; @@ -69,25 +69,11 @@ public function map( $template ); - $localizedObject = $dimensionContentCollection->getDimensionContent($dimensionAttributes); - - if ($localizedObject) { - if (!$localizedObject instanceof TemplateInterface) { - throw new \RuntimeException(\sprintf('Expected "$localizedObject" from type "%s" but "%s" given.', TemplateInterface::class, \get_class($localizedObject))); - } - - $localizedObject->setTemplateKey($template); - $localizedObject->setTemplateData($localizedData); - } - - if (!$localizedObject) { - // Only set templateKey to unlocalizedDimension when no localizedDimension exist - $unlocalizedObject->setTemplateKey($template); - } + $localizedDimensionContent->setTemplateKey($template); + $localizedDimensionContent->setTemplateData($localizedData); - // Unlocalized dimensions can contain data of different templates so we need to merge them together - $unlocalizedObject->setTemplateData(\array_merge( - $unlocalizedObject->getTemplateData(), + $unlocalizedDimensionContent->setTemplateData(\array_merge( + $unlocalizedDimensionContent->getTemplateData(), $unlocalizedData )); } diff --git a/Content/Application/ContentDataMapper/DataMapper/WorkflowDataMapper.php b/Content/Application/ContentDataMapper/DataMapper/WorkflowDataMapper.php index 36cffc34..184364cd 100644 --- a/Content/Application/ContentDataMapper/DataMapper/WorkflowDataMapper.php +++ b/Content/Application/ContentDataMapper/DataMapper/WorkflowDataMapper.php @@ -13,7 +13,6 @@ namespace Sulu\Bundle\ContentBundle\Content\Application\ContentDataMapper\DataMapper; -use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowInterface; @@ -21,29 +20,14 @@ class WorkflowDataMapper implements DataMapperInterface { public function map( array $data, - DimensionContentCollectionInterface $dimensionContentCollection + DimensionContentInterface $unlocalizedDimensionContent, + DimensionContentInterface $localizedDimensionContent ): void { - $dimensionAttributes = $dimensionContentCollection->getDimensionAttributes(); - $unlocalizedDimensionAttributes = \array_merge($dimensionAttributes, ['locale' => null]); - $unlocalizedObject = $dimensionContentCollection->getDimensionContent($unlocalizedDimensionAttributes); - - if (!$unlocalizedObject instanceof WorkflowInterface) { - return; - } - - $localizedObject = $dimensionContentCollection->getDimensionContent($dimensionAttributes); - - if ($localizedObject) { - if (!$localizedObject instanceof WorkflowInterface) { - throw new \RuntimeException(\sprintf('Expected "$localizedObject" from type "%s" but "%s" given.', WorkflowInterface::class, \get_class($localizedObject))); - } - - $this->setWorkflowData($localizedObject, $data); - + if (!$localizedDimensionContent instanceof WorkflowInterface) { return; } - $this->setWorkflowData($unlocalizedObject, $data); + $this->setWorkflowData($localizedDimensionContent, $data); } /**