vendor/contao/core-bundle/src/Controller/FrontendModule/AbstractFrontendModuleController.php line 23

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\FrontendModule;
  11. use Contao\BackendTemplate;
  12. use Contao\CoreBundle\Controller\AbstractFragmentController;
  13. use Contao\ModuleModel;
  14. use Contao\Template;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Contracts\Translation\TranslatorInterface;
  18. abstract class AbstractFrontendModuleController extends AbstractFragmentController
  19. {
  20.     public function __invoke(Request $requestModuleModel $modelstring $section, array $classes null): Response
  21.     {
  22.         if ($this->get('contao.routing.scope_matcher')->isBackendRequest($request)) {
  23.             return $this->getBackendWildcard($model);
  24.         }
  25.         $type $this->getType();
  26.         $template $this->createTemplate($model'mod_'.$type);
  27.         $this->addHeadlineToTemplate($template$model->headline);
  28.         $this->addCssAttributesToTemplate($template'mod_'.$type$model->cssID$classes);
  29.         $this->addPropertiesToTemplate($template$request->attributes->get('templateProperties', []));
  30.         $this->addSectionToTemplate($template$section);
  31.         $this->tagResponse(['contao.db.tl_module.'.$model->id]);
  32.         $response $this->getResponse($template$model$request);
  33.         if (null === $response) {
  34.             $response $template->getResponse();
  35.         }
  36.         return $response;
  37.     }
  38.     public static function getSubscribedServices(): array
  39.     {
  40.         $services parent::getSubscribedServices();
  41.         $services['translator'] = TranslatorInterface::class;
  42.         return $services;
  43.     }
  44.     protected function getBackendWildcard(ModuleModel $module): Response
  45.     {
  46.         $href $this->get('router')->generate(
  47.             'contao_backend',
  48.             ['do' => 'themes''table' => 'tl_module''act' => 'edit''id' => $module->id]
  49.         );
  50.         $name $this->get('translator')->trans('FMD.'.$this->getType().'.0', [], 'contao_modules');
  51.         $template = new BackendTemplate('be_wildcard');
  52.         $template->wildcard '### '.strtoupper($name).' ###';
  53.         $template->id $module->id;
  54.         $template->link $module->name;
  55.         $template->href $href;
  56.         return new Response($template->parse());
  57.     }
  58.     abstract protected function getResponse(Template $templateModuleModel $modelRequest $request): ?Response;
  59. }