"Fossies" - the Fresh Open Source Software Archive

Member "contao-4.11.5/core-bundle/src/Controller/FrontendModule/AbstractFrontendModuleController.php" (23 Jun 2021, 2491 Bytes) of package /linux/www/contao-4.11.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AbstractFrontendModuleController.php" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 4.11.2_vs_4.11.3.

    1 <?php
    2 
    3 declare(strict_types=1);
    4 
    5 /*
    6  * This file is part of Contao.
    7  *
    8  * (c) Leo Feyer
    9  *
   10  * @license LGPL-3.0-or-later
   11  */
   12 
   13 namespace Contao\CoreBundle\Controller\FrontendModule;
   14 
   15 use Contao\BackendTemplate;
   16 use Contao\CoreBundle\Controller\AbstractFragmentController;
   17 use Contao\ModuleModel;
   18 use Contao\Template;
   19 use Symfony\Component\HttpFoundation\Request;
   20 use Symfony\Component\HttpFoundation\Response;
   21 use Symfony\Contracts\Translation\TranslatorInterface;
   22 
   23 abstract class AbstractFrontendModuleController extends AbstractFragmentController
   24 {
   25     public function __invoke(Request $request, ModuleModel $model, string $section, array $classes = null): Response
   26     {
   27         if ($this->get('contao.routing.scope_matcher')->isBackendRequest($request)) {
   28             return $this->getBackendWildcard($model);
   29         }
   30 
   31         $type = $this->getType();
   32         $template = $this->createTemplate($model, 'mod_'.$type);
   33 
   34         $this->addHeadlineToTemplate($template, $model->headline);
   35         $this->addCssAttributesToTemplate($template, 'mod_'.$type, $model->cssID, $classes);
   36         $this->addPropertiesToTemplate($template, $request->attributes->get('templateProperties', []));
   37         $this->addSectionToTemplate($template, $section);
   38         $this->tagResponse(['contao.db.tl_module.'.$model->id]);
   39 
   40         $response = $this->getResponse($template, $model, $request);
   41 
   42         if (null === $response) {
   43             $response = $template->getResponse();
   44         }
   45 
   46         return $response;
   47     }
   48 
   49     public static function getSubscribedServices(): array
   50     {
   51         $services = parent::getSubscribedServices();
   52 
   53         $services['translator'] = TranslatorInterface::class;
   54 
   55         return $services;
   56     }
   57 
   58     protected function getBackendWildcard(ModuleModel $module): Response
   59     {
   60         $href = $this->get('router')->generate(
   61             'contao_backend',
   62             ['do' => 'themes', 'table' => 'tl_module', 'act' => 'edit', 'id' => $module->id]
   63         );
   64 
   65         $name = $this->get('translator')->trans('FMD.'.$this->getType().'.0', [], 'contao_modules');
   66 
   67         $template = new BackendTemplate('be_wildcard');
   68         $template->wildcard = '### '.strtoupper($name).' ###';
   69         $template->id = $module->id;
   70         $template->link = $module->name;
   71         $template->href = $href;
   72 
   73         return new Response($template->parse());
   74     }
   75 
   76     abstract protected function getResponse(Template $template, ModuleModel $model, Request $request): ?Response;
   77 }