/** * {@inheritDoc} */ public function reverseTransform($value) { $metadataCollection = $this->property->getMetadata(); // @FIXME: absolutely not performance-wise $metadataCollection->clear(); if ($value && is_array($value)) { // @TODO: some input data validation is needed. foreach (array_values($value) as $key => $itemData) { if (!isset($itemData['image']) || !is_array($itemData['image'])) { throw new TransformationFailedException(sprintf('Missing image data for item [%s]', $key)); } $imageData = $itemData['image']; if (empty($imageData['id'])) { throw new TransformationFailedException(sprintf('Image ID is missing for element [%s].', $key)); } $image = $this->getFileStorage()->findImage($imageData['id']); if ($image === null) { throw new TransformationFailedException(sprintf('Image [%s] not found in file storage.', $imageData['id'])); } $element = new ImageReferencedElement(); $element->fillFromArray($imageData); if (!empty($itemData['title'])) { $element->setTitle($itemData['title']); } if (!empty($itemData['description'])) { $element->setDescription($itemData['description']); } $metadataCollection->set($key, new BlockPropertyMetadata($key, $this->property, $element)); } } return null; }
/** * @param array $data * @return null */ protected function reverseTransformImageData(array $data) { $element = new ImageReferencedElement(); // @TODO: some data validation must happen here. $element->fillFromArray($data); $this->getMediaMetadata()->setReferencedElement($element); }
public function reverseTransform($value) { if (empty($value)) { $this->property->getMetadata()->remove('image'); return null; } $metadata = $this->property->getMetadata(); if (!$metadata->offsetExists('image')) { $metadata->set('image', new BlockPropertyMetadata('image', $this->property)); } $metaItem = $metadata->get('image'); /* @var $metaItem BlockPropertyMetadata */ $element = new ImageReferencedElement(); // @TODO: some data validation must happen here. $element->fillFromArray($value); $metaItem->setReferencedElement($element); return null; }