Skip to content

Commit

Permalink
Fix #67, use current contenttype in getCurrentLocaleStructure
Browse files Browse the repository at this point in the history
Fixes the getCurrentLocaleStructure so that it actually uses the
contenttype we are on. Fixes #67
  • Loading branch information
SvanteRichter committed Aug 21, 2016
1 parent a2e117c commit 03388c4
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/TranslateExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,21 @@ public function getCurrentLocaleStructure()
$requestAttributes = $request->attributes->get('_route_params');
$requestLocale = $request->get('_locale');
if ($config->isTranslateSlugs() && $locale->getSlug() !== $requestLocale && $request->get('slug')) {
$repo = $app['storage']->getRepository('pages');
$qb = $repo->createQueryBuilder();
$qb->select($locale->getSlug() . '_slug')
->where($app['translate.slug'] . '_slug = ?')
->setParameter(0, $request->get('slug'))
;
$newSlug = $repo->findOneWith($qb);
if ($newSlug) {
$requestAttributes['slug'] = $newSlug[$locale->getSlug() . '_slug'];
foreach ($app['config']->get('contenttypes') as $key => $ct) {
if ($request->get('contenttypeslug') !== $ct['slug'] && $request->get('contenttypeslug') !== $ct['singular_slug']) {
continue;
}

$repo = $app['storage']->getRepository($ct['slug']);
$qb = $repo->createQueryBuilder();
$qb->select($locale->getSlug() . '_slug')
->where($request->get('_locale') . '_slug = ?')
->setParameter(0, $request->get('slug'))
;
$newSlug = $repo->findOneWith($qb);
if ($newSlug) {
$requestAttributes['slug'] = $newSlug[$locale->getSlug() . '_slug'];
}
}
}

Expand Down

0 comments on commit 03388c4

Please sign in to comment.