Skip to content

Commit d7f91c4

Browse files
committed
Merge pull request #342 from symfony-cmf/frontend_link_i18n
Use content locale for frontend link
2 parents 4d877f8 + b0fb38f commit d7f91c4

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ env:
2121
matrix:
2222
include:
2323
- php: 5.6
24-
env: DEPS=dev
24+
env: SYMFONY_VERSION=2.8.* DEPS=dev
2525
- php: 5.3
2626
env: COMPOSER_FLAGS="--prefer-lowest"
2727
- php: 5.6

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)