]> Raphaƫl G. Git Repositories - userbundle/blobdiff - Controller/AbstractController.php
Cleanup
[userbundle] / Controller / AbstractController.php
index a859e5a20ce40f2740cdac4a201e0d961445a7dc..77cf860f4d59bcc66dc67fefd4ddb2e384d3fff4 100644 (file)
@@ -14,6 +14,10 @@ namespace Rapsys\UserBundle\Controller;
 use Doctrine\ORM\EntityManagerInterface;
 use Doctrine\Persistence\ManagerRegistry;
 
 use Doctrine\ORM\EntityManagerInterface;
 use Doctrine\Persistence\ManagerRegistry;
 
+use Rapsys\PackBundle\Util\SluggerUtil;
+
+use Rapsys\UserBundle\RapsysUserBundle;
+
 use Psr\Container\ContainerInterface;
 use Psr\Log\LoggerInterface;
 
 use Psr\Container\ContainerInterface;
 use Psr\Log\LoggerInterface;
 
@@ -36,16 +40,17 @@ use Symfony\Contracts\Translation\TranslatorInterface;
 
 use Twig\Environment;
 
 
 use Twig\Environment;
 
-use Rapsys\PackBundle\Util\SluggerUtil;
-
-use Rapsys\UserBundle\RapsysUserBundle;
-
 /**
 /**
- * Provides common features needed in controllers.
- *
  * {@inheritdoc}
  * {@inheritdoc}
+ *
+ * Provides common features needed in controllers.
  */
 abstract class AbstractController extends BaseAbstractController implements ServiceSubscriberInterface {
  */
 abstract class AbstractController extends BaseAbstractController implements ServiceSubscriberInterface {
+       /**
+        * Alias string
+        */
+       protected string $alias;
+
        /**
         * Config array
         */
        /**
         * Config array
         */
@@ -66,6 +71,11 @@ abstract class AbstractController extends BaseAbstractController implements Serv
         */
        protected int $page;
 
         */
        protected int $page;
 
+       /**
+        * Request instance
+        */
+       protected Request $request;
+
        /**
         * Abstract constructor
         *
        /**
         * Abstract constructor
         *
@@ -88,7 +98,7 @@ abstract class AbstractController extends BaseAbstractController implements Serv
         */
        public function __construct(protected CacheInterface $cache, protected AuthorizationCheckerInterface $checker, protected ContainerInterface $container, protected ManagerRegistry $doctrine, protected FormFactoryInterface $factory, protected UserPasswordHasherInterface $hasher, protected LoggerInterface $logger, protected MailerInterface $mailer, protected EntityManagerInterface $manager, protected RouterInterface $router, protected Security $security, protected SluggerUtil $slugger, protected RequestStack $stack, protected TranslatorInterface $translator, protected Environment $twig, protected int $limit = 5) {
                //Retrieve config
         */
        public function __construct(protected CacheInterface $cache, protected AuthorizationCheckerInterface $checker, protected ContainerInterface $container, protected ManagerRegistry $doctrine, protected FormFactoryInterface $factory, protected UserPasswordHasherInterface $hasher, protected LoggerInterface $logger, protected MailerInterface $mailer, protected EntityManagerInterface $manager, protected RouterInterface $router, protected Security $security, protected SluggerUtil $slugger, protected RequestStack $stack, protected TranslatorInterface $translator, protected Environment $twig, protected int $limit = 5) {
                //Retrieve config
-               $this->config = $container->getParameter(RapsysUserBundle::getAlias());
+               $this->config = $container->getParameter($this->alias = RapsysUserBundle::getAlias());
 
                //Get current request
                $this->request = $stack->getCurrentRequest();
 
                //Get current request
                $this->request = $stack->getCurrentRequest();
@@ -193,7 +203,7 @@ abstract class AbstractController extends BaseAbstractController implements Serv
                                                                }
 
                                                                //Translate tmp value
                                                                }
 
                                                                //Translate tmp value
-                                                               $tmp = $this->translator->trans($tmp);
+                                                               $tmp = $this->translator->trans($tmp, [], $this->alias);
 
                                                                //Iterate on keys
                                                                foreach(array_reverse($keys) as $curkey) {
 
                                                                //Iterate on keys
                                                                foreach(array_reverse($keys) as $curkey) {
@@ -218,7 +228,7 @@ abstract class AbstractController extends BaseAbstractController implements Serv
 
                                                                //Iterate on other locales
                                                                foreach(array_diff($locales, [$locale]) as $other) {
 
                                                                //Iterate on other locales
                                                                foreach(array_diff($locales, [$locale]) as $other) {
-                                                                       $titles[$other] = $this->translator->trans($this->config['default']['languages'][$locale], [], null, $other);
+                                                                       $titles[$other] = $this->translator->trans($this->config['default']['languages'][$locale], [], $this->alias, $other);
                                                                }
 
                                                                //Retrieve route matching path
                                                                }
 
                                                                //Retrieve route matching path
@@ -234,13 +244,14 @@ abstract class AbstractController extends BaseAbstractController implements Serv
                                                                if ($locale == $this->locale) {
                                                                        //Set locale locales context
                                                                        $this->config[$tag][$view]['context']['canonical'] = $this->router->generate($name, ['_locale' => $locale]+$route, UrlGeneratorInterface::ABSOLUTE_URL);
                                                                if ($locale == $this->locale) {
                                                                        //Set locale locales context
                                                                        $this->config[$tag][$view]['context']['canonical'] = $this->router->generate($name, ['_locale' => $locale]+$route, UrlGeneratorInterface::ABSOLUTE_URL);
+                                                                       $this->config[$tag][$view]['context']['self_url'] = $this->router->generate($name, ['_locale' => $locale]+$route);
                                                                } else {
                                                                        //Set locale locales context
                                                                        $this->config[$tag][$view]['context']['alternates'][$locale] = [
                                                                                'absolute' => $this->router->generate($name, ['_locale' => $locale]+$route, UrlGeneratorInterface::ABSOLUTE_URL),
                                                                                'relative' => $this->router->generate($name, ['_locale' => $locale]+$route),
                                                                                'title' => implode('/', $titles),
                                                                } else {
                                                                        //Set locale locales context
                                                                        $this->config[$tag][$view]['context']['alternates'][$locale] = [
                                                                                'absolute' => $this->router->generate($name, ['_locale' => $locale]+$route, UrlGeneratorInterface::ABSOLUTE_URL),
                                                                                'relative' => $this->router->generate($name, ['_locale' => $locale]+$route),
                                                                                'title' => implode('/', $titles),
-                                                                               'translated' => $this->translator->trans($this->config['default']['languages'][$locale], [], null, $locale)
+                                                                               'translated' => $this->translator->trans($this->config['default']['languages'][$locale], [], $this->alias, $locale)
                                                                        ];
                                                                }
 
                                                                        ];
                                                                }
 
@@ -251,7 +262,7 @@ abstract class AbstractController extends BaseAbstractController implements Serv
                                                                                'absolute' => $this->router->generate($name, ['_locale' => $locale]+$route, UrlGeneratorInterface::ABSOLUTE_URL),
                                                                                'relative' => $this->router->generate($name, ['_locale' => $locale]+$route),
                                                                                'title' => implode('/', $titles),
                                                                                'absolute' => $this->router->generate($name, ['_locale' => $locale]+$route, UrlGeneratorInterface::ABSOLUTE_URL),
                                                                                'relative' => $this->router->generate($name, ['_locale' => $locale]+$route),
                                                                                'title' => implode('/', $titles),
-                                                                               'translated' => $this->translator->trans($this->config['default']['languages'][$locale], [], null, $locale)
+                                                                               'translated' => $this->translator->trans($this->config['default']['languages'][$locale], [], $this->alias, $locale)
                                                                        ];
                                                                }
                                                        }
                                                                        ];
                                                                }
                                                        }
@@ -263,9 +274,9 @@ abstract class AbstractController extends BaseAbstractController implements Serv
        }
 
        /**
        }
 
        /**
-        * Renders a view
-        *
         * {@inheritdoc}
         * {@inheritdoc}
+        *
+        * Renders a view
         */
        protected function render(string $view, array $parameters = [], Response $response = null): Response {
                //Create response when null
         */
        protected function render(string $view, array $parameters = [], Response $response = null): Response {
                //Create response when null
@@ -277,17 +288,6 @@ abstract class AbstractController extends BaseAbstractController implements Serv
                        $parameters['locale'] = $this->locale;
                }
 
                        $parameters['locale'] = $this->locale;
                }
 
-               /*TODO: XXX: to drop, we have title => [ 'page' => XXX, section => XXX, site => XXX ]
-               //With empty head title and section
-               if (empty($parameters['head']['title']) && !empty($parameters['section'])) {
-                       //Set head title
-                       $parameters['title'] = implode(' - ', [$parameters['title'], $parameters['section'], $parameters['head']['site']]);
-               //With empty head title
-               } elseif (empty($parameters['head']['title'])) {
-                       //Set head title
-                       $parameters['head']['title'] = implode(' - ', [$parameters['title'], $parameters['head']['site']]);
-               }*/
-
                //Call twig render method
                $content = $this->twig->render($view, $parameters);
 
                //Call twig render method
                $content = $this->twig->render($view, $parameters);