From 0ded6855e6ce135ccdea5dac36d7ef01e49af34d Mon Sep 17 00:00:00 2001 From: Alfonso Machado Date: Thu, 6 Sep 2018 12:18:58 +0200 Subject: [PATCH] fix errors with current locale in translatable object --- src/Adapter/OrmAdapter.php | 25 ++++++++++++++----------- src/Resources/config/orm.xml | 1 - 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Adapter/OrmAdapter.php b/src/Adapter/OrmAdapter.php index 1410222..8524aa3 100644 --- a/src/Adapter/OrmAdapter.php +++ b/src/Adapter/OrmAdapter.php @@ -45,20 +45,14 @@ class OrmAdapter implements AdapterInterface */ private $autoRouteFqcn; - /** - * @var ContentRouteEnhancer - */ - private $contentRouteEnhancer; - /** * @param EntityManagerInterface $em * @param ContentRouteEnhancer $contentRouteEnhancer * @param string $autoRouteFqcn The FQCN of the AutoRoute document to use */ - public function __construct(EntityManagerInterface $em, ContentRouteEnhancer $contentRouteEnhancer, $autoRouteFqcn = 'WAM\Bundle\RoutingBundle\Entity\AutoRoute') + public function __construct(EntityManagerInterface $em, $autoRouteFqcn = 'WAM\Bundle\RoutingBundle\Entity\AutoRoute') { $this->em = $em; - $this->contentRouteEnhancer = $contentRouteEnhancer; // $this->baseRoutePath = $routeBasePath; $reflection = new \ReflectionClass($autoRouteFqcn); @@ -87,9 +81,7 @@ public function getLocales($contentDocument) */ public function translateObject($contentDocument, $locale) { - $contentDocument->setCurrentLocale($locale); - - return $contentDocument->translate(null, false); + return $contentDocument->translate($locale, false); } /** @@ -253,12 +245,23 @@ public function getReferringAutoRoutes($contentDocument) public function findRouteForUri($uri, UriContext $uriContext) { if ($route = $this->em->getRepository($this->autoRouteFqcn)->findOneByStaticPrefix($uri)) { - $this->contentRouteEnhancer->resolveRouteContent($route); + $this->resolveRouteContent($route); } return $route; } + protected function resolveRouteContent(AutoRouteInterface $routeObject) + { + if ($class = $routeObject->getContentClass()) { + $objectRepository = $this->em->getRepository($class); + if ($id = $routeObject->getContentId()) { + $object = $objectRepository->find($id); + $routeObject->setContent($object); + } + } + } + /** * @param $autoRouteTag * @param $item diff --git a/src/Resources/config/orm.xml b/src/Resources/config/orm.xml index 9dfe7ad..d28f7bd 100644 --- a/src/Resources/config/orm.xml +++ b/src/Resources/config/orm.xml @@ -8,7 +8,6 @@ - %cmf_routing.auto_route_entity.class%