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

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\RedirectResponse;
  23. use Symfony\Component\HttpFoundation\Request;
  24. use Symfony\Component\HttpFoundation\Response;
  25. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  26. use Symfony\Component\HttpKernel\UriSigner;
  27. use Symfony\Component\Routing\Annotation\Route;
  28. /**
  29.  * @Route(path="%contao.backend.route_prefix%", defaults={"_scope" = "backend", "_token_check" = true})
  30.  *
  31.  * @internal
  32.  */
  33. class BackendController extends AbstractController
  34. {
  35.     /**
  36.      * @Route("", 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("/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->container->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("/logout", name="contao_backend_logout")
  67.      */
  68.     public function logoutAction(): RedirectResponse
  69.     {
  70.         return $this->redirectToRoute('contao_backend_login');
  71.     }
  72.     /**
  73.      * @Route("/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("/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("/file", name="contao_backend_file")
  92.      *
  93.      * @deprecated Deprecated since Contao 4.13, to be removed in Contao 5.0.
  94.      *             Use the picker instead.
  95.      */
  96.     public function fileAction(): Response
  97.     {
  98.         trigger_deprecation('contao/core-bundle''4.13''Calling "%s()" has been deprecated and will no longer work in Contao 5.0. Use the picker instead.'__METHOD__);
  99.         $this->initializeContaoFramework();
  100.         $controller = new BackendFile();
  101.         return $controller->run();
  102.     }
  103.     /**
  104.      * @Route("/help", name="contao_backend_help")
  105.      */
  106.     public function helpAction(): Response
  107.     {
  108.         $this->initializeContaoFramework();
  109.         $controller = new BackendHelp();
  110.         return $controller->run();
  111.     }
  112.     /**
  113.      * @Route("/page", name="contao_backend_page")
  114.      *
  115.      * @deprecated Deprecated since Contao 4.13, to be removed in Contao 5.0.
  116.      *             Use the picker instead.
  117.      */
  118.     public function pageAction(): Response
  119.     {
  120.         trigger_deprecation('contao/core-bundle''4.13''Calling "%s::%s()" has been deprecated and will no longer work in Contao 5.0. Use the picker instead.'__CLASS____METHOD__);
  121.         $this->initializeContaoFramework();
  122.         $controller = new BackendPage();
  123.         return $controller->run();
  124.     }
  125.     /**
  126.      * @Route("/popup", name="contao_backend_popup")
  127.      */
  128.     public function popupAction(): Response
  129.     {
  130.         $this->initializeContaoFramework();
  131.         $controller = new BackendPopup();
  132.         return $controller->run();
  133.     }
  134.     /**
  135.      * @Route("/alerts", name="contao_backend_alerts")
  136.      */
  137.     public function alertsAction(): Response
  138.     {
  139.         $this->initializeContaoFramework();
  140.         $controller = new BackendAlerts();
  141.         return $controller->run();
  142.     }
  143.     /**
  144.      * Redirects the user to the Contao back end and adds the picker query parameter.
  145.      * It will determine the current provider URL based on the value, which is usually
  146.      * read dynamically via JavaScript.
  147.      *
  148.      * @Route("/picker", name="contao_backend_picker")
  149.      */
  150.     public function pickerAction(Request $request): RedirectResponse
  151.     {
  152.         $extras = [];
  153.         if ($request->query->has('extras')) {
  154.             $extras $request->query->all('extras');
  155.             if (empty($extras)) {
  156.                 throw new BadRequestHttpException('Invalid picker extras');
  157.             }
  158.         }
  159.         $config = new PickerConfig($request->query->get('context'), $extras$request->query->get('value'));
  160.         $picker $this->container->get('contao.picker.builder')->create($config);
  161.         if (null === $picker) {
  162.             throw new BadRequestHttpException('Unsupported picker context');
  163.         }
  164.         return new RedirectResponse($picker->getCurrentUrl());
  165.     }
  166.     public static function getSubscribedServices(): array
  167.     {
  168.         $services parent::getSubscribedServices();
  169.         $services['contao.picker.builder'] = PickerBuilderInterface::class;
  170.         $services['uri_signer'] = UriSigner::class;
  171.         return $services;
  172.     }
  173. }