Neos\Neos\TypeConverter\EntityToIdentityConverter::convertFrom PHP Method

convertFrom() public method

Converts the given source object to an array containing the type and identity.
public convertFrom ( object $source, string $targetType, array $convertedChildProperties = [], Neos\Flow\Property\PropertyMappingConfigurationInterface $configuration = null ) : array
$source object
$targetType string
$convertedChildProperties array
$configuration Neos\Flow\Property\PropertyMappingConfigurationInterface
return array
    public function convertFrom($source, $targetType, array $convertedChildProperties = array(), PropertyMappingConfigurationInterface $configuration = null)
    {
        return ['__identity' => $this->persistenceManager->getIdentifierByObject($source), '__type' => TypeHandling::getTypeForValue($source)];
    }

Usage Example

 /**
  * Generate a new image variant from given data.
  *
  * @param ImageVariant $asset
  * @return string
  */
 public function createImageVariantAction(ImageVariant $asset)
 {
     if ($this->persistenceManager->isNewObject($asset)) {
         $this->assetRepository->add($asset);
     }
     $propertyMappingConfiguration = new PropertyMappingConfiguration();
     // This will not be sent as "application/json" as we need the JSON string and not the single variables.
     return json_encode($this->entityToIdentityConverter->convertFrom($asset, 'array', [], $propertyMappingConfiguration));
 }
EntityToIdentityConverter