vendor/pimcore/portal-engine/src/Controller/PortalController.php line 42

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under following license:
  6.  * - Pimcore Commercial License (PCL)
  7.  *
  8.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  9.  *  @license    http://www.pimcore.org/license     PCL
  10.  */
  11. namespace Pimcore\Bundle\PortalEngineBundle\Controller;
  12. use Pimcore\Bundle\PortalEngineBundle\Service\Document\LanguageVariantService;
  13. use Pimcore\Bundle\PortalEngineBundle\Service\PortalConfig\DefaultValuesService;
  14. use Pimcore\Bundle\PortalEngineBundle\Service\PortalConfig\FrontendBuildService;
  15. use Pimcore\Bundle\PortalEngineBundle\Service\PortalConfig\PortalConfigService;
  16. use Pimcore\Bundle\PortalEngineBundle\Service\Security\SecurityService;
  17. use Pimcore\Http\Request\Resolver\DocumentResolver;
  18. use Pimcore\Model\Document\PageSnippet;
  19. use Pimcore\Model\Site;
  20. use Pimcore\Tool;
  21. use Symfony\Component\HttpFoundation\RedirectResponse;
  22. use Symfony\Component\HttpFoundation\Request;
  23. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  24. class PortalController extends AbstractSiteController
  25. {
  26.     public function onKernelControllerEvent(ControllerEvent $event)
  27.     {
  28.         if (!Site::isSiteRequest() && !Tool::isFrontendRequestByAdmin()) {
  29.             $this->throwNotInSiteException($event);
  30.         }
  31.     }
  32.     /**
  33.      * @return RedirectResponse|\Symfony\Component\HttpFoundation\Response
  34.      *
  35.      * @throws \Exception
  36.      */
  37.     public function pageAction(
  38.         Request $request,
  39.         DocumentResolver $documentResolver,
  40.         DefaultValuesService $defaultConfigService,
  41.         FrontendBuildService $frontendBuildService,
  42.         PortalConfigService $portalConfigService,
  43.         LanguageVariantService $languageVariantService,
  44.         SecurityService $securityService
  45.     ) {
  46.         $document $documentResolver->getDocument($request);
  47.         if (!$document instanceof PageSnippet) {
  48.             throw new \Exception('Invalid Document');
  49.         }
  50.         $defaultConfigService->setPortalPageDefaultConfig($document);
  51.         if (!$this->editmode && !$request->get('pimcore_preview') && $portalConfigService->getCurrentPortalConfig()->getEnableLanguageRedirect()) {
  52.             $mapping $languageVariantService->getPortalLanguageVariantsMapping();
  53.             $languages array_keys($mapping);
  54.             $preferredLanguage in_array($securityService->getPortalUser()->getPreferredLanguage(), $languages)
  55.                 ? $securityService->getPortalUser()->getPreferredLanguage()
  56.                 : $request->getPreferredLanguage($languages);
  57.             return new RedirectResponse($mapping[$preferredLanguage]);
  58.         }
  59.         $customizedFrontendBuilds = [[null'-']];
  60.         foreach ($frontendBuildService->getCustomizedFrontendBuilds() as $build) {
  61.             $customizedFrontendBuilds[] = [$build$build];
  62.         }
  63.         $oidcEnabled class_exists('Pimcore\\Bundle\\OpenIdConnectBundle\\PimcoreOpenIdConnectBundle');
  64.         return $this->renderTemplate('@PimcorePortalEngine/portal/page.html.twig', [
  65.             'customizedFrontendBuilds' => $customizedFrontendBuilds,
  66.             'oidcEnabled' => $oidcEnabled
  67.         ]);
  68.     }
  69.     /**
  70.      * @return \Symfony\Component\HttpFoundation\Response
  71.      */
  72.     public function contentAction()
  73.     {
  74.         return $this->renderTemplate('@PimcorePortalEngine/portal/content.html.twig');
  75.     }
  76. }