示例#1
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;
 }