vendor/contao/core-bundle/src/Controller/BackendController.php line 74

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of Contao.
  5.  *
  6.  * (c) Leo Feyer
  7.  *
  8.  * @license LGPL-3.0-or-later
  9.  */
  10. namespace Contao\CoreBundle\Controller;
  11. use Contao\BackendAlerts;
  12. use Contao\BackendConfirm;
  13. use Contao\BackendFile;
  14. use Contao\BackendHelp;
  15. use Contao\BackendIndex;
  16. use Contao\BackendMain;
  17. use Contao\BackendPage;
  18. use Contao\BackendPassword;
  19. use Contao\BackendPopup;
  20. use Contao\CoreBundle\Picker\PickerBuilderInterface;
  21. use Contao\CoreBundle\Picker\PickerConfig;
  22. use Symfony\Component\HttpFoundation\InputBag;
  23. use Symfony\Component\HttpFoundation\RedirectResponse;
  24. use Symfony\Component\HttpFoundation\Request;
  25. use Symfony\Component\HttpFoundation\Response;
  26. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  27. use Symfony\Component\Routing\Annotation\Route;
  28. /**
  29.  * @Route(defaults={"_scope" = "backend", "_token_check" = true})
  30.  *
  31.  * @internal
  32.  */
  33. class BackendController extends AbstractController
  34. {
  35.     /**
  36.      * @Route("/contao", name="contao_backend")
  37.      */
  38.     public function mainAction(): Response
  39.     {
  40.         $this->initializeContaoFramework();
  41.         $controller = new BackendMain();
  42.         return $controller->run();
  43.     }
  44.     /**
  45.      * @Route("/contao/login", name="contao_backend_login")
  46.      */
  47.     public function loginAction(Request $request): Response
  48.     {
  49.         $this->initializeContaoFramework();
  50.         if ($this->isGranted('IS_AUTHENTICATED_FULLY')) {
  51.             if ($request->query->has('redirect')) {
  52.                 $uriSigner $this->get('uri_signer');
  53.                 // We cannot use $request->getUri() here as we want to work with the original URI (no query string reordering)
  54.                 if ($uriSigner->check($request->getSchemeAndHttpHost().$request->getBaseUrl().$request->getPathInfo().(null !== ($qs $request->server->get('QUERY_STRING')) ? '?'.$qs ''))) {
  55.                     return new RedirectResponse($request->query->get('redirect'));
  56.                 }
  57.             }
  58.             return new RedirectResponse($this->generateUrl('contao_backend'));
  59.         }
  60.         $controller = new BackendIndex();
  61.         return $controller->run();
  62.     }
  63.     /**
  64.      * Symfony will un-authenticate the user automatically by calling this route.
  65.      *
  66.      * @Route("/contao/logout", name="contao_backend_logout")
  67.      */
  68.     public function logoutAction(): RedirectResponse
  69.     {
  70.         return $this->redirectToRoute('contao_backend_login');
  71.     }
  72.     /**
  73.      * @Route("/contao/password", name="contao_backend_password")
  74.      */
  75.     public function passwordAction(): Response
  76.     {
  77.         $this->initializeContaoFramework();
  78.         $controller = new BackendPassword();
  79.         return $controller->run();
  80.     }
  81.     /**
  82.      * @Route("/contao/confirm", name="contao_backend_confirm")
  83.      */
  84.     public function confirmAction(): Response
  85.     {
  86.         $this->initializeContaoFramework();
  87.         $controller = new BackendConfirm();
  88.         return $controller->run();
  89.     }
  90.     /**
  91.      * @Route("/contao/file", name="contao_backend_file")
  92.      */
  93.     public function fileAction(): Response
  94.     {
  95.         $this->initializeContaoFramework();
  96.         $controller = new BackendFile();
  97.         return $controller->run();
  98.     }
  99.     /**
  100.      * @Route("/contao/help", name="contao_backend_help")
  101.      */
  102.     public function helpAction(): Response
  103.     {
  104.         $this->initializeContaoFramework();
  105.         $controller = new BackendHelp();
  106.         return $controller->run();
  107.     }
  108.     /**
  109.      * @Route("/contao/page", name="contao_backend_page")
  110.      */
  111.     public function pageAction(): Response
  112.     {
  113.         $this->initializeContaoFramework();
  114.         $controller = new BackendPage();
  115.         return $controller->run();
  116.     }
  117.     /**
  118.      * @Route("/contao/popup", name="contao_backend_popup")
  119.      */
  120.     public function popupAction(): Response
  121.     {
  122.         $this->initializeContaoFramework();
  123.         $controller = new BackendPopup();
  124.         return $controller->run();
  125.     }
  126.     /**
  127.      * @Route("/contao/alerts", name="contao_backend_alerts")
  128.      */
  129.     public function alertsAction(): Response
  130.     {
  131.         $this->initializeContaoFramework();
  132.         $controller = new BackendAlerts();
  133.         return $controller->run();
  134.     }
  135.     /**
  136.      * Redirects the user to the Contao back end and adds the picker query parameter.
  137.      * It will determine the current provider URL based on the value, which is usually
  138.      * read dynamically via JavaScript.
  139.      *
  140.      * @throws BadRequestHttpException
  141.      *
  142.      * @Route("/contao/picker", name="contao_backend_picker")
  143.      */
  144.     public function pickerAction(Request $request): RedirectResponse
  145.     {
  146.         $extras = [];
  147.         if ($request->query->has('extras')) {
  148.             if ($request->query instanceof InputBag) {
  149.                 $extras $request->query->all('extras');
  150.             } else { /** @phpstan-ignore-line */
  151.                 // Backwards compatibility with symfony/http-foundation <5.0
  152.                 $extras $request->query->get('extras');
  153.             }
  154.             if (empty($extras) || !\is_array($extras)) {
  155.                 throw new BadRequestHttpException('Invalid picker extras');
  156.             }
  157.         }
  158.         $config = new PickerConfig($request->query->get('context'), $extras$request->query->get('value'));
  159.         $picker $this->get('contao.picker.builder')->create($config);
  160.         if (null === $picker) {
  161.             throw new BadRequestHttpException('Unsupported picker context');
  162.         }
  163.         return new RedirectResponse($picker->getCurrentUrl());
  164.     }
  165.     public static function getSubscribedServices(): array
  166.     {
  167.         $services parent::getSubscribedServices();
  168.         $services['contao.picker.builder'] = PickerBuilderInterface::class;
  169.         $services['uri_signer'] = 'uri_signer'// TODO: adjust this once we are on Symfony 5 only (see https://github.com/symfony/symfony/pull/35298)
  170.         return $services;
  171.     }
  172. }