vendor/contao/core-bundle/src/Resources/contao/elements/ContentModule.php line 101

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Contao.
  4.  *
  5.  * (c) Leo Feyer
  6.  *
  7.  * @license LGPL-3.0-or-later
  8.  */
  9. namespace Contao;
  10. /**
  11.  * Front end content element "module".
  12.  *
  13.  * @author Leo Feyer <https://github.com/leofeyer>
  14.  */
  15. class ContentModule extends ContentElement
  16. {
  17.     /**
  18.      * Parse the template
  19.      *
  20.      * @return string
  21.      */
  22.     public function generate()
  23.     {
  24.         if ($this->isHidden())
  25.         {
  26.             return '';
  27.         }
  28.         $objModel ModuleModel::findByPk($this->module);
  29.         if ($objModel === null)
  30.         {
  31.             return '';
  32.         }
  33.         $strClass Module::findClass($objModel->type);
  34.         if (!class_exists($strClass))
  35.         {
  36.             return '';
  37.         }
  38.         if (is_a($strClassContentProxy::class, true))
  39.         {
  40.             if (!empty($this->cssID[1]))
  41.             {
  42.                 $objModel->classes array_merge((array) $objModel->classes, array($this->cssID[1]));
  43.             }
  44.             /** @var ContentProxy $proxy */
  45.             $proxy = new $strClass($objModel$this->strColumn);
  46.             if (!empty($this->cssID[0]))
  47.             {
  48.                 $proxy->cssID ' id="' $this->cssID[0] . '"';
  49.             }
  50.             return $proxy->generate();
  51.         }
  52.         $cssID StringUtil::deserialize($objModel->cssIDtrue);
  53.         // Override the CSS ID (see #305)
  54.         if (!empty($this->cssID[0]))
  55.         {
  56.             $cssID[0] = $this->cssID[0];
  57.         }
  58.         // Merge the CSS classes (see #6011)
  59.         if (!empty($this->cssID[1]))
  60.         {
  61.             $cssID[1] = trim(($cssID[1] ?? '') . ' ' $this->cssID[1]);
  62.         }
  63.         // Clone the model so we do not modify the shared model in the registry
  64.         $objModel $objModel->cloneOriginal();
  65.         $objModel->cssID $cssID;
  66.         $objModel->typePrefix 'ce_';
  67.         $strStopWatchId 'contao.frontend_module.' $objModel->type ' (ID ' $objModel->id ')';
  68.         if (System::getContainer()->getParameter('kernel.debug'))
  69.         {
  70.             $objStopwatch System::getContainer()->get('debug.stopwatch');
  71.             $objStopwatch->start($strStopWatchId'contao.layout');
  72.         }
  73.         /** @var Module $objModule */
  74.         $objModule = new $strClass($objModel$this->strColumn);
  75.         // Tag the content element (see #2137)
  76.         if (System::getContainer()->has('fos_http_cache.http.symfony_response_tagger'))
  77.         {
  78.             $responseTagger System::getContainer()->get('fos_http_cache.http.symfony_response_tagger');
  79.             $responseTagger->addTags(array('contao.db.tl_content.' $this->id));
  80.         }
  81.         $strBuffer $objModule->generate();
  82.         if (isset($objStopwatch) && $objStopwatch->isStarted($strStopWatchId))
  83.         {
  84.             $objStopwatch->stop($strStopWatchId);
  85.         }
  86.         return $strBuffer;
  87.     }
  88.     /**
  89.      * Generate the content element
  90.      */
  91.     protected function compile()
  92.     {
  93.     }
  94. }
  95. class_alias(ContentModule::class, 'ContentModule');