Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance route generation #156

Merged
merged 3 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Sulu\Bundle\ContentBundle\Content\Application\ContentDataMapper\DataMapper;

use Sulu\Bundle\ContentBundle\Content\Application\ContentNormalizer\ContentNormalizerInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\RoutableInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface;
use Sulu\Bundle\RouteBundle\Generator\RouteGeneratorInterface;
Expand All @@ -38,6 +39,11 @@ class RoutableDataMapper implements DataMapperInterface
*/
private $routeManager;

/**
* @var ContentNormalizerInterface
*/
private $contentNormalizer;

/**
* @var array<string, string>
*/
Expand All @@ -56,12 +62,14 @@ public function __construct(
StructureMetadataFactoryInterface $factory,
RouteGeneratorInterface $routeGenerator,
RouteManagerInterface $routeManager,
ContentNormalizerInterface $contentNormalizer,
array $structureDefaultTypes,
array $routeMappings
) {
$this->factory = $factory;
$this->routeGenerator = $routeGenerator;
$this->routeManager = $routeManager;
$this->contentNormalizer = $contentNormalizer;
$this->structureDefaultTypes = $structureDefaultTypes;
$this->routeMappings = $routeMappings;
}
Expand Down Expand Up @@ -138,8 +146,14 @@ public function map(

$routePath = $data[$name] ?? null;
if (!$routePath) {
/** @var mixed $routeGenerationData */
$routeGenerationData = array_merge(
luca-rath marked this conversation as resolved.
Show resolved Hide resolved
$this->contentNormalizer->normalize($unlocalizedObject),
$this->contentNormalizer->normalize($localizedObject)
);

$routePath = $this->routeGenerator->generate(
$localizedObject,
$routeGenerationData,
Copy link
Contributor

@niklasnatter niklasnatter Jun 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think passing something like this here would be more pragmatic and flexible:

array_merge(
    $data,
    ['_unlocalizedDimensionContent' => $unlocalizedObject, '_localizedDimensionContent' => $localizedObject]
)

this way the route_schema can still access all template properties (and also the seo properties if he really wants to 😅 ). if somebody needs to access a property that is not available in the $data (which should be a edge case), he probably also knows if he needs to access the _unlocalizedDimensionContent or the _localizedDimensionContent.

$routeSchema
);

Expand Down
1 change: 1 addition & 0 deletions Resources/config/data-mapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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 type="service" id="sulu_content.content_normalizer"/>
<argument>%sulu.content.structure.default_types%</argument>
<argument>%sulu_route.mappings%</argument>

Expand Down
Loading