protected function prepareData(ClassMetadata $metadata, array $data) { foreach ($data as $name => &$entityData) { switch ($metadata->name) { case Localization::CN(): case PageLocalization::CN(): case TemplateLocalization::CN(): case ApplicationLocalization::CN(): $entityData['publishedRevision'] = null; $args = array($entityData['locale']); break; case PageLocalizationPath::CN(): $args = array(str_ireplace('pageLocalizationPath', '', $name), $entityData['locale']); break; case TemplateLayout::CN(): $args = array($entityData['media']); break; case BlockPropertyMetadata::CN(): $args = array($entityData['name'], $entityData['blockProperty']); break; case BlockProperty::CN(): $args = array($entityData['name']); break; case PagePlaceHolder::CN(): case TemplatePlaceHolder::CN(): $args = array($entityData['name']); break; default: $constructor = new \ReflectionMethod($metadata->name, '__construct'); if ($constructor->getNumberOfRequiredParameters() === 0) { return parent::prepareData($metadata, $data); } throw new \RuntimeException(sprintf('Don\'t know how to build constructor required for [%s].', $metadata->name)); } $entityData = array_merge(array('__construct' => $args), $entityData); } return parent::prepareData($metadata, $data); }
/** * @param BlockPropertyMetadata $metadata */ public function addMetadata(BlockPropertyMetadata $metadata) { $name = $metadata->getName(); $this->metadata->offsetSet($name, $metadata); }
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; }