public function filter($content, array $options = array()) { if ($this->blockProperty->getMetadata()->offsetExists('image')) { $element = $this->blockProperty->getMetadata()->get('image')->getReferencedElement(); if ($element !== null) { /* @var $element ImageReferencedElement */ if (!$element instanceof ImageReferencedElement) { // @TODO: any exception should be thrown probably return null; } $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; } } return null; }
/** * {@inheritDoc} */ public function filter($content, array $options = array()) { if ($this->blockProperty->getMetadata()->offsetExists('link')) { $element = $this->blockProperty->getMetadata()->get('link')->getReferencedElement(); if ($element !== null) { /* @var $element LinkReferencedElement */ if (!$element instanceof LinkReferencedElement) { // @TODO: any exception should be thrown probably return null; } // @TODO: the same code is inside HtmlFilter, should combine somehow. $title = ReferencedElementUtils::getLinkReferencedElementTitle($element, $this->container->getDoctrine()->getManager(), $this->container->getLocaleManager()->getCurrentLocale()); // @TODO: what if we failed to obtain the URL? $url = ReferencedElementUtils::getLinkReferencedElementUrl($element, $this->container->getDoctrine()->getManager(), $this->container->getLocaleManager()->getCurrentLocale()); $tag = new HtmlTag('a', $title ? $title : $url); $tag->setAttribute('title', $title)->setAttribute('href', $url)->setAttribute('class', $element->getClassName()); $target = $element->getTarget(); if (!empty($target)) { $tag->setAttribute('target', $target); } switch ($element->getResource()) { case LinkReferencedElement::RESOURCE_FILE: $tag->setAttribute('target', '_blank'); break; } return $tag; } } return null; }
/** * @param string $content * @param array $options * @return string */ public function filter($content, array $options = array()) { $elements = array(); foreach ($this->blockProperty->getMetadata() as $key => $item) { $elements[$key] = $item->getReferencedElement(); } return $this->parseSupraMarkup($content, $elements); }
/** * @param mixed $value * @return null|array */ public function transform($value) { if ($value !== null) { // @TODO: not sure if this one is needed. just double checking. throw new \LogicException('Expecting link containing block property value to be null.'); } if ($this->property->getMetadata()->offsetExists('link')) { $metaItem = $this->property->getMetadata()->get('link'); $element = $metaItem->getReferencedElement(); return $element !== null ? $element->toArray() : null; } return null; }
/** * @return BlockPropertyMetadata */ private function getMediaMetadata() { if (!$this->property->getMetadata()->offsetExists('media')) { $this->property->addMetadata(new BlockPropertyMetadata('media', $this->property)); } return $this->property->getMetadata()->get('media'); }
/** * @return BlockPropertyMetadata */ private function getFontsMetadata() { $metaCollection = $this->property->getMetadata(); if ($metaCollection->containsKey('fonts')) { return $metaCollection->get('fonts'); } return new BlockPropertyMetadata('fonts', $this->property); }
/** * @param mixed $value * @return null|array */ public function transform($value) { $metadata = $this->property->getMetadata(); if (!isset($metadata['media'])) { return null; } $element = $metadata['media']->getReferencedElement(); return $element ? $element->toArray() : null; }
/** * {@inheritDoc} */ public function transform($value) { $imageDataArray = array(); $fileStorage = $this->getFileStorage(); foreach ($this->property->getMetadata() as $metadata) { /* @var $metadata BlockPropertyMetadata */ $element = $metadata->getReferencedElement(); if (!$element instanceof ImageReferencedElement) { throw new TransformationFailedException(sprintf('Expecting only image referenced elements, [%s] received.', $element ? get_class($element) : 'NULL')); } $image = $fileStorage->findImage($element->getImageId()); if ($image === null) { $this->container->getLogger()->warn("Image [{$element->getImageId()}] not found."); continue; } $imageDataArray[] = array('title' => $element->getTitle(), 'description' => $element->getDescription(), 'image' => array_merge($element->toArray(), array('image' => $fileStorage->getFileInfo($image)))); } return $imageDataArray; }
/** * @param mixed $value * @return null|array */ public function transform($value) { if ($value !== null) { // @TODO: not sure if this one is needed. just double checking. throw new \LogicException('Expecting image containing block property value to be null.'); } if ($this->property->getMetadata()->offsetExists('image')) { $metaItem = $this->property->getMetadata()->get('image'); $element = $metaItem->getReferencedElement(); if ($element instanceof ImageReferencedElement) { $fileStorage = $this->container['cms.file_storage']; /* @var $fileStorage \Supra\Package\Cms\FileStorage\FileStorage */ $image = $fileStorage->findImage($element->getImageId()); if ($image !== null) { return array_merge($element->toArray(), array('image' => $fileStorage->getFileInfo($image))); } } } return null; }
/** * {@inheritDoc} */ public function filter($content, array $options = array()) { $metadata = $this->property->getMetadata(); if (!isset($metadata['media'])) { return null; } $element = $metadata['media']->getReferencedElement(); if (!$element instanceof MediaReferencedElement) { return null; } $mediaEmbed = $this->container['cms.media_embed']; /* @var $mediaEmbed MediaEmbed */ $mediaObject = $mediaEmbed->parseUrl($element->getUrl()); if ($mediaObject === null) { return null; } $mediaObject->setWidth($element->getWidth()); $mediaObject->setHeight($element->getHeight()); return $mediaObject->getEmbedCode(); }
/** * {@inheritDoc} * @return string */ public function filter($content, array $options = array()) { $itemTemplate = !empty($options['itemTemplate']) ? (string) $options['itemTemplate'] : ''; $wrapperTemplate = !empty($options['wrapperTemplate']) ? (string) $options['wrapperTemplate'] : ''; $output = ''; $fileStorage = $this->container['cms.file_storage']; /* @var $fileStorage \Supra\Package\Cms\FileStorage\FileStorage */ foreach ($this->blockProperty->getMetadata() as $metadata) { /* @var $metadata \Supra\Package\Cms\Entity\BlockPropertyMetadata */ $element = $metadata->getReferencedElement(); if (!$element instanceof ImageReferencedElement || $element->getSizeName() === null) { continue; } $image = $fileStorage->findImage($element->getImageId()); if ($image === null) { continue; } $previewSize = $image->getImageSize($element->getSizeName()); if ($previewSize === null) { continue; } $previewUrl = $fileStorage->getWebPath($image, $previewSize); $crop = isset($options['fullSizeCrop']) ? (bool) $options['fullSizeCrop'] : true; $fullSizeWidth = !empty($options['fullSizeMaxWidth']) ? (int) $options['fullSizeMaxWidth'] : null; $fullSizeHeight = !empty($options['fullSizeMaxHeight']) ? (int) $options['fullSizeMaxWidth'] : null; try { list($width, $height) = $this->getFullSizeDimensions($image, $fullSizeWidth, $fullSizeHeight, $crop); $fullSizeName = $fileStorage->createResizedImage($image, $width, $height, $crop); } catch (FileStorageException $e) { $this->container->getLogger()->warn($e->getMessage()); continue; } $fullSize = $image->getImageSize($fullSizeName); $fullSizeUrl = $fileStorage->getWebPath($image, $fullSize); $itemData = array('image' => '<img src="' . $previewUrl . '" alt="' . $element->getAlternateText() . '" />', 'imageUrl' => $previewUrl, 'title' => $element->getTitle(), 'description' => $element->getDescription(), 'fullSizeUrl' => $fullSizeUrl, 'fullSizeWidth' => $fullSize->getWidth(), 'fullSizeHeight' => $fullSize->getHeight()); $output .= preg_replace_callback('/{{\\s*(image|title|description|fullSizeUrl|fullSizeWidth|fullSizeHeight)\\s*}}/', function ($matches) use($itemData) { return $itemData[$matches[1]]; }, $itemTemplate); } return preg_replace('/{{\\s*items\\s*}}/', $output, $wrapperTemplate); }
public function filter($content, array $options = array()) { if ($this->blockProperty->getMetadata()->offsetExists('image')) { $element = $this->blockProperty->getMetadata()->get('image')->getReferencedElement(); if ($element !== null) { /* @var $element ImageReferencedElement */ if (!$element instanceof ImageReferencedElement) { // @TODO: any exception should be thrown probably return null; } $imageId = $element->getImageId(); $fileStorage = $this->container['cms.file_storage']; /* @var $fileStorage \Supra\Package\Cms\FileStorage\FileStorage */ $image = $fileStorage->findImage($imageId); if ($image) { $tag = new ImageTag($image, $fileStorage); $tag->setAttribute('alt', $element->getAlternateText()); return $tag; } } } return null; }
/** * @param MediaReferencedElement $element * @return null|string */ protected function handleMediaElement(MediaReferencedElement $element) { $mediaEmbed = $this->container['cms.media_embed']; /* @var $mediaEmbed MediaEmbed */ $mediaObject = $mediaEmbed->parseUrl($element->getUrl()); if ($mediaObject === null) { return null; } $metadata = $this->property->getMetadata(); if ($metadata->offsetExists('width')) { $width = (int) $metadata->get('width')->getValue(); $mediaObject->setWidth($width); } if ($metadata->offsetExists('height')) { $height = (int) $metadata->get('height')->getValue(); $mediaObject->setHeight($height); } return $mediaObject->getEmbedCode(); }