vendor/contao/core-bundle/src/Resources/contao/elements/ContentImage.php line 75

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. use Contao\CoreBundle\Image\Studio\Studio;
  11. /**
  12.  * Front end content element "image".
  13.  *
  14.  * @author Leo Feyer <https://github.com/leofeyer>
  15.  */
  16. class ContentImage extends ContentElement
  17. {
  18.     /**
  19.      * Template
  20.      * @var string
  21.      */
  22.     protected $strTemplate 'ce_image';
  23.     /**
  24.      * Files model
  25.      * @var FilesModel
  26.      */
  27.     protected $objFilesModel;
  28.     /**
  29.      * Return if the image does not exist
  30.      *
  31.      * @return string
  32.      */
  33.     public function generate()
  34.     {
  35.         if (!$this->singleSRC)
  36.         {
  37.             return '';
  38.         }
  39.         $objFile FilesModel::findByUuid($this->singleSRC);
  40.         if ($objFile === null || !is_file(System::getContainer()->getParameter('kernel.project_dir') . '/' $objFile->path))
  41.         {
  42.             return '';
  43.         }
  44.         $this->singleSRC $objFile->path;
  45.         $this->objFilesModel $objFile;
  46.         return parent::generate();
  47.     }
  48.     /**
  49.      * Generate the content element
  50.      */
  51.     protected function compile()
  52.     {
  53.         $figure System::getContainer()
  54.             ->get(Studio::class)
  55.             ->createFigureBuilder()
  56.             ->from($this->objFilesModel)
  57.             ->setSize($this->size)
  58.             ->setMetadata($this->objModel->getOverwriteMetadata())
  59.             ->enableLightbox((bool) $this->fullsize)
  60.             ->buildIfResourceExists();
  61.         if (null !== $figure)
  62.         {
  63.             $figure->applyLegacyTemplateData($this->Template$this->imagemargin);
  64.         }
  65.     }
  66. }
  67. class_alias(ContentImage::class, 'ContentImage');