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 Twig\Environment;
-use Rapsys\PackBundle\Util\SluggerUtil;
-
-use Rapsys\UserBundle\RapsysUserBundle;
-
/**
- * Provides common features needed in controllers.
- *
* {@inheritdoc}
+ *
+ * Provides common features needed in controllers.
*/
abstract class AbstractController extends BaseAbstractController implements ServiceSubscriberInterface {
+ /**
+ * Alias string
+ */
+ protected string $alias;
+
/**
* Config array
*/
*/
protected int $page;
+ /**
+ * Request instance
+ */
+ protected Request $request;
+
/**
* Abstract constructor
*
*/
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();
}
//Translate tmp value
- $tmp = $this->translator->trans($tmp);
+ $tmp = $this->translator->trans($tmp, [], $this->alias);
//Iterate on keys
foreach(array_reverse($keys) as $curkey) {
$pathInfo = $this->router->getContext()->getPathInfo();
//Iterate on locales excluding current one
- foreach(($locales = array_keys($this->config['languages'])) as $locale) {
+ foreach(($locales = array_keys($this->config['default']['languages'])) as $locale) {
//Set titles
$titles = [];
//Iterate on other locales
foreach(array_diff($locales, [$locale]) as $other) {
- $titles[$other] = $this->translator->trans($this->config['languages'][$locale], [], null, $other);
+ $titles[$other] = $this->translator->trans($this->config['default']['languages'][$locale], [], $this->alias, $other);
}
//Retrieve route matching path
//With current locale
if ($locale == $this->locale) {
//Set locale locales context
- $this->config[$tag][$view]['context']['head']['canonical'] = $this->router->generate($name, ['_locale' => $locale]+$route, UrlGeneratorInterface::ABSOLUTE_URL);
+ $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']['head']['alternates'][$locale] = [
+ $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['languages'][$locale], [], null, $locale)
+ 'translated' => $this->translator->trans($this->config['default']['languages'][$locale], [], $this->alias, $locale)
];
}
//Add shorter locale
- if (empty($this->config[$tag][$view]['context']['head']['alternates'][$slocale = substr($locale, 0, 2)])) {
+ if (empty($this->config[$tag][$view]['context']['alternates'][$slocale = substr($locale, 0, 2)])) {
//Add shorter locale
- $this->config[$tag][$view]['context']['head']['alternates'][$slocale] = [
+ $this->config[$tag][$view]['context']['alternates'][$slocale] = [
'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['languages'][$locale], [], null, $locale)
+ 'translated' => $this->translator->trans($this->config['default']['languages'][$locale], [], $this->alias, $locale)
];
}
}
}
/**
- * Renders a view
- *
* {@inheritdoc}
+ *
+ * Renders a view
*/
protected function render(string $view, array $parameters = [], Response $response = null): Response {
//Create response when null
$response ??= new Response();
//With empty head locale
- if (empty($parameters['head']['locale'])) {
+ if (empty($parameters['locale'])) {
//Set head locale
- $parameters['head']['locale'] = $this->locale;
- }
-
- //With empty head title and section
- if (empty($parameters['head']['title']) && !empty($parameters['section'])) {
- //Set head title
- $parameters['head']['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']]);
+ $parameters['locale'] = $this->locale;
}
//Call twig render method