|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
-
- namespace Lc\SovBundle\Twig;
-
- use App\Repository\ReminderRepository;
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\SovBundle\Model\Reminder\ReminderInterface;
- use Lc\SovBundle\Repository\Reminder\ReminderStore;
- use Lc\SovBundle\Translation\TranslatorAdmin;
- use Liip\ImagineBundle\Imagine\Cache\CacheManager;
- use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
- use Symfony\Component\HttpFoundation\RequestStack;
- use Symfony\Component\HttpKernel\KernelInterface;
- use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
- use Symfony\Component\Security\Core\Security;
- use Symfony\Contracts\Translation\TranslatorInterface;
- use Twig\Extension\AbstractExtension;
- use Twig\TwigFilter;
- use Twig\TwigFunction;
-
- class TranslatorTwigExtension extends AbstractExtension
- {
- protected $parameterBag;
- protected $requestStack;
- protected $router;
- protected $translatorAdmin;
-
- public function __construct(
- ParameterBagInterface $parameterBag,
- RequestStack $requestStack,
- UrlGeneratorInterface $router,
- TranslatorAdmin $translatorAdmin
- ) {
- $this->parameterBag = $parameterBag;
- $this->requestStack = $requestStack;
- $this->router = $router;
- $this->translatorAdmin = $translatorAdmin;
- }
-
- public function getFunctions()
- {
- return [
- new TwigFunction('sov_translated_urls', [$this, 'getTranslatedUrls']),
- ];
- }
-
-
- public function getFilters()
- {
- return [
- new TwigFilter('sov_trans_admin_field', [$this, 'transAdminField']),
- new TwigFilter('sov_trans_admin_help', [$this, 'transAdminHelp']),
- new TwigFilter('sov_trans_admin_panel', [$this, 'transAdminPanel']),
- new TwigFilter('sov_trans_admin_menu', [$this, 'transAdminMenu']),
- new TwigFilter('sov_trans_admin_title', [$this, 'transAdminTitle']),
- new TwigFilter('sov_trans_admin_action', [$this, 'transAdminAction']),
- ];
- }
-
- function getTranslatedUrls()
- {
- $ret = array();
- $langs = $this->parameterBag->get('app.locales');
- $currentRoute = $this->requestStack->getCurrentRequest()->get('_route');
-
- $params = array_merge((array)$this->requestStack->getCurrentRequest()->get('_route_params'), $_GET);
-
- if ($currentRoute) {
- foreach ($langs as $lg) {
- $ret[$lg] = $this->router->generate($currentRoute, array_merge($params, array('_locale' => $lg)));
- }
- }
-
- return $ret;
- }
-
- public function transAdminField($fieldName, $entityClass)
- {
- return $this->translatorAdmin->transField($fieldName, $entityClass);
- }
-
- public function transAdminHelp($fieldName, $entityClass)
- {
- return $this->translatorAdmin->transHelp($fieldName, $entityClass);
- }
-
- public function transAdminPanel($panelName, $entityClass)
- {
- return $this->translatorAdmin->transPanel($panelName, $entityClass);
- }
-
- public function transAdminMenu($menuName)
- {
- return $this->translatorAdmin->transMenu($menuName);;
- }
-
- public function transAdminAction($actionName)
- {
- return $this->translatorAdmin->transAction($actionName);;
- }
-
- public function transAdminTitle($pageName, $entityClass = null, $params = [])
- {
- return $this->translatorAdmin->transTitle($pageName, $entityClass, $params);
- }
-
- }
|