/**
  * @param mixed $value
  * @return null
  */
 public function reverseTransform($value)
 {
     if (empty($value)) {
         $this->property->getMetadata()->clear();
         return null;
     }
     if (!is_array($value)) {
         throw new TransformationFailedException(sprintf('Expected array only, got [%s]', gettype($value)));
     }
     if (!isset($value['url'])) {
         throw new TransformationFailedException('Media URL is missing.');
     }
     $mediaEmbed = $this->container['cms.media_embed'];
     /* @var $mediaEmbed MediaEmbed */
     $mediaObject = $mediaEmbed->parseUrl($value['url']);
     if ($mediaObject === null) {
         throw new TransformationFailedException(sprintf('Failed to parse media URL [%s].', $value['url']));
     }
     $metadata = $this->property->getMetadata();
     $mediaElement = new MediaReferencedElement();
     $mediaElement->setUrl($value['url']);
     if (isset($value['width'])) {
         $width = (int) $value['width'];
         if ($width < 1) {
             throw new TransformationFailedException(sprintf('Invalid width value: [%s]', $value['width']));
         }
         $mediaElement->setWidth($width);
     }
     if (isset($value['height'])) {
         $height = (int) $value['height'];
         if ($height < 1) {
             throw new TransformationFailedException(sprintf('Invalid height value: [%s]', $value['height']));
         }
         $mediaElement->setHeight($height);
     }
     if (!isset($metadata['media'])) {
         $this->property->addMetadata(new BlockPropertyMetadata('media', $this->property));
     }
     $metadata['media']->setReferencedElement($mediaElement);
     return $value['url'];
 }
 public function reverseTransform($value)
 {
     // used fonts list
     // @FIXME: sanitize list
     $fonts = !empty($value['fonts']) ? $value['fonts'] : array();
     $this->getFontsMetadata()->setValue(serialize($fonts));
     // additional metadata
     $metadata = $this->property->getMetadata();
     // @TODO: not performance-wise.
     $metadata->clear();
     if (!empty($value['data'])) {
         foreach ($value['data'] as $name => $itemData) {
             if (empty($itemData['type'])) {
                 throw new TransformationFailedException(sprintf('No type specified for HTML metadata element [%s].', $name));
             }
             $element = null;
             switch ($itemData['type']) {
                 case ImageReferencedElement::TYPE_ID:
                 case LinkReferencedElement::TYPE_ID:
                     $element = ReferencedElementAbstract::fromArray($itemData);
                     break;
                 case 'video':
                     // @TODO: BC. Remove.
                 // @TODO: BC. Remove.
                 case MediaReferencedElement::TYPE_ID:
                     if (empty($itemData['url'])) {
                         throw new TransformationFailedException(sprintf('No media URL specified for item [%s].', $name));
                     }
                     $mediaEmbed = $this->container['cms.media_embed'];
                     /* @var $mediaEmbed MediaEmbed */
                     $mediaObject = $mediaEmbed->parseUrl($itemData['url']);
                     if ($mediaObject === null) {
                         throw new TransformationFailedException(sprintf('Failed to parse media URL [%s].', $itemData['url']));
                     }
                     $element = new MediaReferencedElement();
                     $element->setUrl($itemData['url']);
                     // width attribute
                     if (isset($itemData['width'])) {
                         $width = (int) $itemData['width'];
                         if ($width < 1) {
                             throw new TransformationFailedException(sprintf('Invalid width value: [%s]', $itemData['width']));
                         }
                         $element->setWidth($width);
                     }
                     // height attribute
                     if (isset($itemData['height'])) {
                         $height = (int) $itemData['height'];
                         if ($height < 1) {
                             throw new TransformationFailedException(sprintf('Invalid height value: [%s]', $itemData['height']));
                         }
                         $element->setHeight($height);
                     }
                     break;
                 default:
                     throw new TransformationFailedException(sprintf('Unrecognized HTML metadata element type [%s].', $itemData['type']));
             }
             $metaItem = new BlockPropertyMetadata($name, $this->property);
             $metaItem->setReferencedElement($element);
             $metadata->set($name, $metaItem);
         }
     }
     // return HTML as is
     return !empty($value['html']) ? $value['html'] : null;
 }