src/Document/Areabrick/Image.php line 35

Open in your IDE?
  1. <?php
  2.     /**
  3.      * project: Pimcore
  4.      * User: EBiermann
  5.      * Year: 2022
  6.      */
  7.     namespace App\Document\Areabrick;
  8.     use Pimcore\Http\Request\Resolver\EditmodeResolver;
  9.     use Pimcore\Model\Asset\Image\Thumbnail\Config;
  10.     use Pimcore\Model\Document\Editable;
  11.     use Pimcore\Model\Document\Editable\Image as EditableImage;
  12.     use Pimcore\Model\Document\Editable\Area\Info;
  13.     use Pimcore\Translation\Translator;
  14.     class Image extends AbstractAreabrick  {
  15.         private $translator;
  16.         private $editmode;
  17.         public function __constructTranslator $translatorEditmodeResolver $editmodeResolver) {
  18.             $this->translator $translator;
  19.             $this->editmode $editmodeResolver->isEditmode();
  20.         }
  21.         public function getName() {
  22.             return 'Image';
  23.         }
  24.         public function getDescription() {
  25.             return 'Image element';
  26.         }
  27.         public function action(Info $info)
  28.         {
  29.             $cssClasses = [];
  30.             $cssStyles = [];
  31.             $hasLink false;
  32.             $thumbnail false;
  33.             $sqip false;
  34.             $linkEditable $this->getDocumentEditable$info->getDocument(), 'link''link');
  35.             if (!$linkEditable->isEmpty()) {
  36.                 $hasLink true;
  37.             }
  38.             if ($this->getDocumentEditable$info->getDocument(), 'checkbox''border')->isChecked()) {
  39.                 array_push$cssClasses'image--border');
  40.             }
  41.             /** @var EditableImage $imageEditable */
  42.             $imageEditable $this->getDocumentEditable$info->getDocument(), 'image''image');
  43.             if (!$imageEditable->isEmpty()) {
  44.                 $image $imageEditable->getImage();
  45.                 if ( $image instanceof \Pimcore\Model\Asset\Image ) {
  46.                     $orientation \App\Website\Tool\Image::getOrientation$image );
  47.                     $ratio       \App\Website\Tool\Image::getRatio$image );
  48.                     $width       $image->getWidth();
  49.                     $height      $image->getHeight();
  50.                     if ( ! $image->isVectorGraphic() ) {
  51.                         $sqip 'data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeD0iMCIgeT0iMCIgdmlld0JveD0iMCAwIDIgMiIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHBhdGggZmlsbD0iI2VjZThlOCIgZD0iTTAgMGgydjJIMHoiLz48L3N2Zz4=';
  52.                     } else {
  53.                         $sqip 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';
  54.                     }
  55.                 }
  56.                 $thumbnailIdentifier 'area-image-' $orientation '-c' $info->getParam'columns' );
  57.                 if ( $this->editmode ) {
  58.                     /**
  59.                      * create non-existant image thumbnail configuration
  60.                      * otherwise we get an error on the frontend
  61.                      */
  62.                     if ( Config::exists$thumbnailIdentifier ) === false ) {
  63.                         $thumbnailConfig = new Config();
  64.                         $thumbnailConfig->setName$thumbnailIdentifier );
  65.                         $thumbnailConfig->save();
  66.                     }
  67.                 }
  68.             }
  69.             if (!$this->editmode) {
  70.                 $thumbnail $thumbnailIdentifier ?? false;
  71.             }
  72.             $info->setParam'thumbnail',  $thumbnail);
  73.             $info->setParam'cssClasses'$cssClasses);
  74.             $info->setParam'cssStyles'$cssStyles);
  75.             $info->setParam'hasLink'$hasLink);
  76.             $info->setParam'lqip'$sqip);
  77.         }
  78.         // executed after a brick is rendered
  79.         public function postRenderAction(Info $info)
  80.         {
  81.         }
  82.         // returns a custom html wrapper element (return an empty string if you don't want a wrapper element)
  83.         public function getHtmlTagOpen(Info $info)
  84.         {
  85.             return '';
  86.         }
  87.         public function getHtmlTagClose(Info $info)
  88.         {
  89.             return '';
  90.         }
  91.     }