forked from stof/StofDoctrineExtensionsBundle
/
TranslationListener.php
43 lines (37 loc) · 1.25 KB
/
TranslationListener.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace Stof\DoctrineExtensionsBundle\Listener;
use Gedmo\Translatable\TranslationListener as BaseTranslationListener;
use Gedmo\Translatable\Mapping\Event\TranslatableAdapter;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
/**
* TranslationListener
*
* @author Christophe COEVOET
*/
class TranslationListener extends BaseTranslationListener
{
public function getTranslationClass(TranslatableAdapter $ea, $class)
{
$class = parent::getTranslationClass($ea, $class);
if ($class === 'Gedmo\\Translatable\\Entity\\Translation') {
return 'Stof\\DoctrineExtensionsBundle\\Entity\\Translation';
} elseif ($class === 'Gedmo\\Translatable\\Document\\Translation') {
return 'Stof\\DoctrineExtensionsBundle\\Document\\Translation';
}
return $class;
}
/**
* Set the translation listener locale from the session.
*
* This method should be attached to the kernel.request event.
*
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
$session = $event->getRequest()->getSession();
if (null !== $session) {
$this->setTranslatableLocale($session->getLocale());
}
}
}