/**
  * @param ImageReferencedElement $element
  * @return null|string
  */
 protected function handleImageElement(ImageReferencedElement $element)
 {
     $imageId = $element->getImageId();
     $fileStorage = $this->container['cms.file_storage'];
     /* @var $fileStorage \Supra\Package\Cms\FileStorage\FileStorage */
     $image = $fileStorage->findImage($imageId);
     if ($image === null) {
         return null;
     }
     $imageSize = $image->findImageSize($element->getSizeName());
     if ($imageSize === null) {
         return null;
     }
     $tag = new HtmlTag('img');
     $width = $imageSize->isCropped() ? $imageSize->getCropWidth() : $imageSize->getWidth();
     $tag->setAttribute('width', $width);
     $height = $imageSize->isCropped() ? $imageSize->getCropHeight() : $imageSize->getCropHeight();
     $tag->setAttribute('height', $height);
     $tag->setAttribute('alt', trim($element->getAlternateText()));
     $tag->setAttribute('src', $fileStorage->getWebPath($image, $imageSize));
     return $tag;
 }
Example #2
0
 /**
  * Parse supra.image
  * 
  * @param ImageReferencedElement $imageData
  * @return null|HtmlTag
  */
 protected function parseSupraImage(ImageReferencedElement $imageData)
 {
     $imageId = $imageData->getImageId();
     $fileStorage = $this->container['cms.file_storage'];
     /* @var $fileStorage \Supra\Package\Cms\FileStorage\FileStorage */
     $image = $fileStorage->findImage($imageId);
     if ($image === null) {
         return null;
     }
     $sizeName = $imageData->getSizeName();
     $size = $image->findImageSize($sizeName);
     if ($size === null) {
         $this->container->getLogger()->warn("Image [{$imageId}] size [{$sizeName}] not found.");
         return null;
     }
     $tag = new HtmlTag('img');
     if ($size->isCropped()) {
         $width = $size->getCropWidth();
         $height = $size->getCropHeight();
     } else {
         $width = $size->getWidth();
         $height = $size->getHeight();
     }
     $src = $fileStorage->getWebPath($image, $size);
     $tag->setAttribute('src', $src);
     $align = $imageData->getAlign();
     if (!empty($align)) {
         if ($align === 'left') {
             $tag->addClass('pull-left');
         } else {
             if ($align === 'right') {
                 $tag->addClass('pull-right');
             } else {
                 if ($align === 'center') {
                     $tag->addClass('center-block');
                     $tag->setAttribute('style', "width: {$width}px;");
                 }
             }
         }
     }
     if (!empty($width)) {
         $tag->setAttribute('width', $width);
     }
     if (!empty($height)) {
         $tag->setAttribute('height', $height);
     }
     $title = trim($imageData->getTitle());
     if (!empty($title)) {
         $tag->setAttribute('title', $title);
     }
     $tag->setAttribute('alt', trim($imageData->getAlternateText()));
     return $tag;
 }