Skip to content

Commit

Permalink
fix errors with current locale in translatable object
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfonso Machado committed Sep 6, 2018
1 parent 488b989 commit 0ded685
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
25 changes: 14 additions & 11 deletions src/Adapter/OrmAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<!--todo este servicio está acoplado a wam/wam/routingBundle por el enhancer-->
<service id="cmf_routing_auto.adapter.orm" class="Symfony\Cmf\Bundle\RoutingAutoBundle\Adapter\OrmAdapter">
<argument type="service" id="doctrine.orm.entity_manager"/>
<argument type="service" id="wam_routing.content.router_enhancer"/>
<argument>%cmf_routing.auto_route_entity.class%</argument>
<tag name="cmf_routing_auto.adapter" alias="doctrine_orm" />
</service>
Expand Down

0 comments on commit 0ded685

Please sign in to comment.