diff --git a/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapper.php b/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapper.php index a6b250ea..543658dd 100644 --- a/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapper.php +++ b/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapper.php @@ -138,8 +138,17 @@ public function map( $routePath = $data[$name] ?? null; if (!$routePath) { + /** @var mixed $routeGenerationData */ + $routeGenerationData = array_merge( + $data, + [ + '_unlocalizedObject' => $unlocalizedObject, + '_localizedObject' => $localizedObject, + ] + ); + $routePath = $this->routeGenerator->generate( - $localizedObject, + $routeGenerationData, $routeSchema ); diff --git a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapperTest.php b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapperTest.php index 69101d53..e8d3aa31 100644 --- a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapperTest.php +++ b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapperTest.php @@ -47,7 +47,7 @@ protected function createRouteDataMapperInstance( 'testKey' => [ 'generator' => 'schema', 'options' => [ - 'route_schema' => '/{object.getTitle()}', + 'route_schema' => '/{object["title"]}', ], 'resource_key' => 'testKey', 'entityClass' => 'mock-content-class', @@ -319,8 +319,13 @@ public function testMapNoRoutePropertyDataAndNoOldRoute(): void $factory->getStructureMetadata('mock-template-type', 'default')->willReturn($metadata->reveal())->shouldBeCalled(); - $routeGenerator->generate($localizedDimensionContentMock, ['route_schema' => '/{object.getTitle()}']) - ->willReturn('/test'); + $routeGenerator->generate( + array_merge($data, [ + '_unlocalizedObject' => $dimensionContent->reveal(), + '_localizedObject' => $localizedDimensionContentMock, + ]), + ['route_schema' => '/{object["title"]}'] + )->willReturn('/test'); $routeManager->createOrUpdateByAttributes( 'mock-content-class', @@ -373,8 +378,13 @@ public function testMapNoRoutePropertyDataAndNoOldRouteIgnoreSlash(): void $factory->getStructureMetadata('mock-template-type', 'default')->willReturn($metadata->reveal())->shouldBeCalled(); - $routeGenerator->generate($localizedDimensionContentMock, ['route_schema' => '/{object.getTitle()}']) - ->willReturn('/'); + $routeGenerator->generate( + array_merge($data, [ + '_unlocalizedObject' => $dimensionContent->reveal(), + '_localizedObject' => $localizedDimensionContentMock, + ]), + ['route_schema' => '/{object["title"]}'] + )->willReturn('/'); $routeManager->createOrUpdateByAttributes(Argument::cetera())->shouldNotBeCalled(); @@ -505,8 +515,13 @@ public function testMapNoRoutePath(): void $localizedDimensionContentMock = $this->wrapRoutableMock($localizedDimensionContent); - $routeGenerator->generate($localizedDimensionContentMock, ['route_schema' => '/{object.getTitle()}']) - ->willReturn('/test'); + $routeGenerator->generate( + array_merge($data, [ + '_unlocalizedObject' => $dimensionContent->reveal(), + '_localizedObject' => $localizedDimensionContentMock, + ]), + ['route_schema' => '/{object["title"]}'] + )->willReturn('/test'); $routeManager->createOrUpdateByAttributes( 'mock-content-class', @@ -559,8 +574,7 @@ public function testMap(): void $localizedDimensionContent->getResourceKey()->willReturn('testKey'); $localizedDimensionContentMock = $this->wrapRoutableMock($localizedDimensionContent); - $routeGenerator->generate($localizedDimensionContentMock, ['schema' => '/{object.getTitle()}']) - ->shouldNotBeCalled(); + $routeGenerator->generate(Argument::any())->shouldNotBeCalled(); $routeManager->createOrUpdateByAttributes( 'mock-content-class', @@ -612,8 +626,7 @@ public function testMapNoTemplateWithDefaultTemplate(): void $localizedDimensionContent->getResourceKey()->willReturn('testKey'); $localizedDimensionContentMock = $this->wrapRoutableMock($localizedDimensionContent); - $routeGenerator->generate($localizedDimensionContentMock, ['schema' => '/{object.getTitle()}']) - ->shouldNotBeCalled(); + $routeGenerator->generate(Argument::any())->shouldNotBeCalled(); $routeManager->createOrUpdateByAttributes( 'mock-content-class', @@ -668,8 +681,13 @@ public function testMapCustomRoute(): void $localizedDimensionContent->getResourceKey()->willReturn('testKey'); $localizedDimensionContentMock = $this->wrapRoutableMock($localizedDimensionContent); - $routeGenerator->generate($localizedDimensionContentMock, ['route_schema' => 'custom/{object.getName()}-{object.getId()}']) - ->willReturn('/custom/testEntity-123'); + $routeGenerator->generate( + array_merge($data, [ + '_unlocalizedObject' => $dimensionContent->reveal(), + '_localizedObject' => $localizedDimensionContentMock, + ]), + ['route_schema' => 'custom/{object["_localizedObject"].getName()}-{object["_unlocalizedObject"].getRoutableId()}'] + )->willReturn('/custom/testEntity-123'); $routeManager->createOrUpdateByAttributes( 'Sulu/Test/TestEntity', @@ -687,7 +705,7 @@ public function testMapCustomRoute(): void 'testKey' => [ 'generator' => 'schema', 'options' => [ - 'route_schema' => 'custom/{object.getName()}-{object.getId()}', + 'route_schema' => 'custom/{object["_localizedObject"].getName()}-{object["_unlocalizedObject"].getRoutableId()}', ], 'resource_key' => 'testKey', 'entityClass' => 'Sulu/Test/TestEntity',