Skip to content

Commit

Permalink
Fix handling of route in draft mode
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Oct 8, 2021
1 parent 58ca022 commit ff3f982
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
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\Entity\Route;
use Sulu\Bundle\RouteBundle\Generator\RouteGeneratorInterface;
use Sulu\Bundle\RouteBundle\Manager\ConflictResolverInterface;
use Sulu\Bundle\RouteBundle\Manager\RouteManagerInterface;
use Sulu\Component\Content\Metadata\Factory\StructureMetadataFactoryInterface;
use Sulu\Component\Content\Metadata\PropertyMetadata;
Expand All @@ -40,30 +42,29 @@ class RoutableDataMapper implements DataMapperInterface
private $routeManager;

/**
* @var array<string, string>
* @var ConflictResolverInterface
*/
private $structureDefaultTypes;
private $conflictResolver;

/**
* @var array<string, array<mixed>>
*/
private $routeMappings;

/**
* @param array<string, string> $structureDefaultTypes
* @param array<string, array<mixed>> $routeMappings
*/
public function __construct(
StructureMetadataFactoryInterface $factory,
RouteGeneratorInterface $routeGenerator,
RouteManagerInterface $routeManager,
array $structureDefaultTypes,
ConflictResolverInterface $conflictResolver,
array $routeMappings
) {
$this->factory = $factory;
$this->routeGenerator = $routeGenerator;
$this->routeManager = $routeManager;
$this->structureDefaultTypes = $structureDefaultTypes;
$this->conflictResolver = $conflictResolver;
$this->routeMappings = $routeMappings;
}

Expand All @@ -80,21 +81,13 @@ public function map(
throw new \RuntimeException('LocalizedDimensionContent needs to extend the TemplateInterface.');
}

if (DimensionContentInterface::STAGE_LIVE !== $localizedDimensionContent->getStage()) {
// return;
}

$type = $localizedDimensionContent::getTemplateType();

/** @var string|null $template */
$template = $data['template'] ?? null;

if (null === $template) {
$template = $this->structureDefaultTypes[$type] ?? null;
}
$template = $localizedDimensionContent->getTemplateKey() ?? null;

if (null === $template) {
throw new \RuntimeException('Expected "template" to be set in the data array.');
throw new \RuntimeException('LocalizedDimensionContent should return the a template.');
}

$metadata = $this->factory->getStructureMetadata($type, $template);
Expand Down Expand Up @@ -171,10 +164,19 @@ public function map(
(string) $localizedDimensionContent->getResourceId(),
$locale,
$routePath,
true
false
);

$routePath = $route->getPath();
} else {
$route = new Route();
$route->setPath($routePath);
$route->setLocale($locale);
$route->setEntityClass($entityClass);
$route->setEntityId((string) $localizedDimensionContent->getResourceId());

$routePath = $this->conflictResolver->resolve($route)
->getPath();
}

$oldData = $localizedDimensionContent->getTemplateData();
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/data-mapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<argument type="service" id="sulu_page.structure.factory"/>
<argument type="service" id="sulu_route.generator.route_generator"/>
<argument type="service" id="sulu_route.manager.route_manager"/>
<argument>%sulu.content.structure.default_types%</argument>
<argument type="service" id="sulu_route.manager.conflict_resolver.auto_increment"/>
<argument>%sulu_route.mappings%</argument>

<tag name="sulu_content.data_mapper" priority="-32"/>
Expand Down
Loading

0 comments on commit ff3f982

Please sign in to comment.