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

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. class ContentModule extends ContentElement
  14. {
  15.     /**
  16.      * Parse the template
  17.      *
  18.      * @return string
  19.      */
  20.     public function generate()
  21.     {
  22.         if ($this->isHidden())
  23.         {
  24.             return '';
  25.         }
  26.         $objModel = ModuleModel::findByPk($this->module);
  27.         if ($objModel === null)
  28.         {
  29.             return '';
  30.         }
  31.         $strClass = Module::findClass($objModel->type);
  32.         if (!class_exists($strClass))
  33.         {
  34.             return '';
  35.         }
  36.         if (is_a($strClass, ModuleProxy::class, true))
  37.         {
  38.             if (!empty($this->cssID[1]))
  39.             {
  40.                 $objModel->classes = array_merge((array) $objModel->classes, array($this->cssID[1]));
  41.             }
  42.             /** @var ModuleProxy $proxy */
  43.             $proxy = new $strClass($objModel, $this->strColumn);
  44.             if (!empty($this->cssID[0]))
  45.             {
  46.                 $proxy->cssID = ' id="' . $this->cssID[0] . '"';
  47.             }
  48.             return $proxy->generate();
  49.         }
  50.         $cssID = StringUtil::deserialize($objModel->cssID, true);
  51.         // Override the CSS ID (see #305)
  52.         if (!empty($this->cssID[0]))
  53.         {
  54.             $cssID[0] = $this->cssID[0];
  55.         }
  56.         // Merge the CSS classes (see #6011)
  57.         if (!empty($this->cssID[1]))
  58.         {
  59.             $cssID[1] = trim(($cssID[1] ?? '') . ' ' . $this->cssID[1]);
  60.         }
  61.         // Clone the model, so we do not modify the shared model in the registry
  62.         $objModel = $objModel->cloneOriginal();
  63.         $objModel->cssID = $cssID;
  64.         $objModel->typePrefix = 'ce_';
  65.         $strStopWatchId = 'contao.frontend_module.' . $objModel->type . ' (ID ' . $objModel->id . ')';
  66.         if (System::getContainer()->getParameter('kernel.debug'))
  67.         {
  68.             $objStopwatch = System::getContainer()->get('debug.stopwatch');
  69.             $objStopwatch->start($strStopWatchId, 'contao.layout');
  70.         }
  71.         /** @var Module $objModule */
  72.         $objModule = new $strClass($objModel, $this->strColumn);
  73.         // Tag the content element (see #2137)
  74.         if ($this->objModel !== null)
  75.         {
  76.             System::getContainer()->get('contao.cache.entity_tags')->tagWithModelInstance($this->objModel);
  77.         }
  78.         $strBuffer = $objModule->generate();
  79.         if (isset($objStopwatch) && $objStopwatch->isStarted($strStopWatchId))
  80.         {
  81.             $objStopwatch->stop($strStopWatchId);
  82.         }
  83.         return $strBuffer;
  84.     }
  85.     /**
  86.      * Generate the content element
  87.      */
  88.     protected function compile()
  89.     {
  90.     }
  91. }
  92. class_alias(ContentModule::class, 'ContentModule');