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

convertFrom() public method

The return value can be one of three types: - an arbitrary object, or a simple type (which has been created while mapping). This is the normal case. - NULL, indicating that this object should *not* be mapped (i.e. a "File Upload" Converter could return NULL if no file has been uploaded, and a silent failure should occur. - An instance of \Neos\Error\Messages\Error -- This will be a user-visible error message later on. Furthermore, it should throw an Exception if an unexpected failure (like a security error) occurred or a configuration issue happened.
public convertFrom ( array $source, string $targetType = 'array', array $convertedChildProperties = [], Neos\Flow\Property\PropertyMappingConfigurationInterface $configuration = null ) : array
$source array
$targetType string
$convertedChildProperties array
$configuration Neos\Flow\Property\PropertyMappingConfigurationInterface
return array the target type, or an error object if a user-error occurred
    public function convertFrom($source, $targetType = 'array', array $convertedChildProperties = array(), PropertyMappingConfigurationInterface $configuration = null)
    {
        $result = array();
        foreach ($source as $processingInstruction) {
            if ($processingInstruction['command'] !== '') {
                $adjustment = null;
                switch ($processingInstruction['command']) {
                    case 'crop':
                        $options = array();
                        $this->transferOptionFromCommandToAdjustment($processingInstruction['options'], $options, 'start.x', 'x');
                        $this->transferOptionFromCommandToAdjustment($processingInstruction['options'], $options, 'start.y', 'y');
                        $this->transferOptionFromCommandToAdjustment($processingInstruction['options'], $options, 'size.width', 'width');
                        $this->transferOptionFromCommandToAdjustment($processingInstruction['options'], $options, 'size.height', 'height');
                        $adjustment = new CropImageAdjustment($options);
                        break;
                    case 'resize':
                        $options = array();
                        $this->transferOptionFromCommandToAdjustment($processingInstruction['options'], $options, 'size.width', 'width');
                        $this->transferOptionFromCommandToAdjustment($processingInstruction['options'], $options, 'size.height', 'height');
                        $adjustment = new ResizeImageAdjustment($options);
                        break;
                }
                if ($adjustment !== null) {
                    $result[] = $adjustment;
                }
            }
        }
        return $result;
    }

Usage Example

 /**
  * Converts and adds ImageAdjustments to the ImageVariant
  *
  * @param ImageInterface $asset
  * @param mixed $source
  * @param array $convertedChildProperties
  * @param PropertyMappingConfigurationInterface $configuration
  * @return ImageInterface|NULL
  */
 protected function applyTypeSpecificHandling($asset, $source, array $convertedChildProperties, PropertyMappingConfigurationInterface $configuration)
 {
     if ($asset instanceof ImageVariant) {
         $adjustments = [];
         if (isset($source['adjustments'])) {
             foreach ($source['adjustments'] as $adjustmentType => $adjustmentOptions) {
                 if (isset($adjustmentOptions['__type'])) {
                     $adjustmentType = $adjustmentOptions['__type'];
                     unset($adjustmentOptions['__type']);
                 }
                 $identity = null;
                 if (isset($adjustmentOptions['__identity'])) {
                     $identity = $adjustmentOptions['__identity'];
                     unset($adjustmentOptions['__identity']);
                 }
                 $adjustment = $this->propertyMapper->convert($adjustmentOptions, $adjustmentType, $configuration);
                 if ($identity !== null) {
                     ObjectAccess::setProperty($adjustment, 'persistence_object_identifier', $identity, true);
                 }
                 $adjustments[] = $adjustment;
             }
         } elseif (isset($source['processingInstructions'])) {
             $adjustments = $this->processingInstructionsConverter->convertFrom($source['processingInstructions'], 'array');
         }
         if (count($adjustments) > 0) {
             $asset->addAdjustments($adjustments);
         }
     }
     return $asset;
 }
All Usage Examples Of Neos\Media\TypeConverter\ProcessingInstructionsConverter::convertFrom