Neos\Media\TypeConverter\ImageInterfaceArrayPresenter::convertFrom PHP Method

convertFrom() public method

Convert an object from \Neos\Media\Domain\Model\ImageInterface to a json representation
public convertFrom ( Neos\Media\Domain\Model\ImageInterface $source, string $targetType, array $convertedChildProperties = [], Neos\Flow\Property\PropertyMappingConfigurationInterface $configuration = null ) : string | Error
$source Neos\Media\Domain\Model\ImageInterface
$targetType string must be 'string'
$convertedChildProperties array
$configuration Neos\Flow\Property\PropertyMappingConfigurationInterface
return string | Neos\Flow\Validation\Error The converted Image, a Validation Error or NULL
    public function convertFrom($source, $targetType, array $convertedChildProperties = array(), PropertyMappingConfigurationInterface $configuration = null)
    {
        $data = array('__identity' => $this->persistenceManager->getIdentifierByObject($source), '__type' => TypeHandling::getTypeForValue($source));
        if ($source instanceof ImageVariant) {
            $data['originalAsset'] = ['__identity' => $this->persistenceManager->getIdentifierByObject($source->getOriginalAsset())];
            $adjustments = array();
            foreach ($source->getAdjustments() as $adjustment) {
                $index = TypeHandling::getTypeForValue($adjustment);
                $adjustments[$index] = array();
                foreach (ObjectAccess::getGettableProperties($adjustment) as $propertyName => $propertyValue) {
                    $adjustments[$index][$propertyName] = $propertyValue;
                }
            }
            $data['adjustments'] = $adjustments;
        }
        return $data;
    }

Usage Example

 /**
  * Convert an object from \Neos\Media\Domain\Model\ImageInterface to a json representation.
  *
  * @param ImageInterface $source
  * @param string $targetType must be 'string'
  * @param array $convertedChildProperties
  * @param PropertyMappingConfigurationInterface $configuration
  * @return string The converted ImageInterface
  */
 public function convertFrom($source, $targetType, array $convertedChildProperties = array(), PropertyMappingConfigurationInterface $configuration = null)
 {
     $data = parent::convertFrom($source, 'array', $convertedChildProperties, $configuration);
     return json_encode($data);
 }
All Usage Examples Of Neos\Media\TypeConverter\ImageInterfaceArrayPresenter::convertFrom