kernel = $kernel; $this->parameterBag = $parameterBag; $this->cacheManager = $cacheManager; $this->em = $entityManager; $this->requestStack = $requestStack; $this->router = $router; $this->translator = $translator; $this->translatorAdmin = $translatorAdmin; $this->formFactory = $formFactory; $this->reminderFactory = $reminderFactory; } public function getFunctions() { return array( new TwigFunction('lc_liip', [$this, 'lcLiip']), new TwigFunction('homepage_route', [$this, 'homepageRoute']), new TwigFunction('page_by_dev_alias', [$this, 'getPageByDevAlias']), new TwigFunction('translated_urls', [$this, 'getTranslatedUrls']), new TwigFunction('sov_get_form_reminder', [$this, 'getFormReminder']), ); } public function getFilters() { return [ new TwigFilter('lc_cache', [$this, 'lcCache']), new TwigFilter('lc_trans_admin_field', [$this, 'lcTransAdminField']), new TwigFilter('lc_trans_admin_help', [$this, 'lcTransAdminHelp']), new TwigFilter('lc_trans_admin_panel', [$this, 'lcTransAdminPanel']), new TwigFilter('lc_trans_admin_menu', [$this, 'lcTransAdminMenu']), new TwigFilter('lc_trans_admin_title', [$this, 'lcTransAdminTitle']), new TwigFilter('lc_trans_admin_action', [$this, 'lcTransAdminAction']), ]; } public function lcCache($file) { $cacheTime = filemtime($this->kernel->getProjectDir() . '/public' . $file); if ($cacheTime) { return $file . '?c=' . $cacheTime; } else { return $file . "?c=0"; } } public function lcTransAdminField($fieldName, $entityClass) { return $this->translatorAdmin->transField($fieldName, $entityClass); } public function lcTransAdminHelp($fieldName, $entityClass) { return $this->translatorAdmin->transHelp($fieldName, $entityClass); } public function lcTransAdminPanel($panelName, $entityClass) { return $this->translatorAdmin->transPanel($panelName, $entityClass); } public function lcTransAdminMenu($menuName) { return $this->translatorAdmin->transMenu($menuName);; } public function lcTransAdminAction($actionName) { return $this->translatorAdmin->transAction($actionName);; } public function lcTransAdminTitle($pageName, $entityClass = null, $params = []) { return $this->translatorAdmin->transTitle($pageName, $entityClass, $params); } public function lcLiip($path, $thumb = 'tile', $default = 'default.jpg') { if (substr($path, 0, 1) === '/') { $path = substr($path, 1); } if ($path) { $fileManagerFolder = substr($this->getFileManagerFolder(), 1); if (strpos($path, $fileManagerFolder) === false) { $path = $fileManagerFolder . '/' . $path; } if (file_exists($path)) { return $this->cacheManager->getBrowserPath($path, $thumb); } } return $this->cacheManager->getBrowserPath($this->getFileManagerFolder() . '/' . $default, $thumb); } 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 getFileManagerFolder() { return $this->parameterBag->get('app.path_uploads'); } public function homepageRoute() { return $this->parameterBag->get('lc_sov.homepage_route'); } public function getFormReminder() { $reminder = $this->reminderFactory->create(); $formReminder = $this->formFactory->create(ReminderAdminFormType::class, $reminder); return $formReminder->createView(); } }