Skip to content

Commit f3624e1

Browse files
committed
Use content locale for frontend link
1 parent 4d877f8 commit f3624e1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Admin/Extension/FrontendLinkExtension.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Knp\Menu\ItemInterface as MenuItemInterface;
1515
use Sonata\AdminBundle\Admin\AdminExtension;
1616
use Sonata\AdminBundle\Admin\AdminInterface;
17+
use Symfony\Cmf\Bundle\CoreBundle\Translatable\TranslatableInterface;
1718
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\PrefixInterface;
1819
use Symfony\Cmf\Component\Routing\RouteReferrersReadInterface;
1920
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
@@ -75,7 +76,7 @@ public function configureTabMenu(
7576
if (!$subject instanceof RouteReferrersReadInterface && !$subject instanceof Route) {
7677
throw new InvalidConfigurationException(
7778
sprintf(
78-
'%s can only be used on subjects which implement Symfony\Cmf\Component\Routing\RouteReferrersReadInterface or Symfony\Component\Routing\Route!',
79+
'%s can only be used on subjects which implement Symfony\Cmf\Component\Routing\RouteReferrersReadInterface or Symfony\Component\Routing\Route.',
7980
__CLASS__
8081
)
8182
);
@@ -86,8 +87,15 @@ public function configureTabMenu(
8687
return;
8788
}
8889

90+
$defaults = array();
91+
if ($subject instanceof TranslatableInterface) {
92+
if ($locale = $subject->getLocale()) {
93+
$defaults['_locale'] = $locale;
94+
}
95+
}
96+
8997
try {
90-
$uri = $this->router->generate($subject);
98+
$uri = $this->router->generate($subject, $defaults);
9199
} catch (RoutingExceptionInterface $e) {
92100
// we have no valid route
93101
return;

0 commit comments

Comments
 (0)