Neos\Neos\Ui\Domain\Service\NodePropertyConversionService::convert PHP Method

convert() public method

Convert raw property values to the correct type according to a node type configuration
public convert ( TYPO3\TYPO3CR\Domain\Model\NodeType $nodeType, string $propertyName, string $rawValue, TYPO3\TYPO3CR\Domain\Service\Context $context ) : mixed
$nodeType TYPO3\TYPO3CR\Domain\Model\NodeType
$propertyName string
$rawValue string
$context TYPO3\TYPO3CR\Domain\Service\Context
return mixed
    public function convert(NodeType $nodeType, $propertyName, $rawValue, Context $context)
    {
        $propertyType = $nodeType->getPropertyType($propertyName);
        switch ($propertyType) {
            case 'string':
                return $rawValue;
            case 'reference':
                return $this->convertReference($rawValue, $context);
            case 'references':
                return $this->convertReferences($rawValue, $context);
            case 'DateTime':
                return $this->convertDateTime($rawValue);
            case 'integer':
                return $this->convertInteger($rawValue);
            case 'boolean':
                return $this->convertBoolean($rawValue);
            case 'array':
                return $this->convertArray($rawValue);
            default:
                $innerType = $propertyType;
                if ($propertyType !== null) {
                    try {
                        $parsedType = \TYPO3\Flow\Utility\TypeHandling::parseType($propertyType);
                        $innerType = $parsedType['elementType'] ?: $parsedType['type'];
                    } catch (\TYPO3\Flow\Utility\Exception\InvalidTypeException $exception) {
                    }
                }
                if ((is_string($rawValue) || is_array($rawValue)) && $this->objectManager->isRegistered($innerType) && $rawValue !== '') {
                    $propertyMappingConfiguration = new MvcPropertyMappingConfiguration();
                    $propertyMappingConfiguration->allowOverrideTargetType();
                    $propertyMappingConfiguration->allowAllProperties();
                    $propertyMappingConfiguration->skipUnknownProperties();
                    $propertyMappingConfiguration->setTypeConverterOption('TYPO3\\Flow\\Property\\TypeConverter\\PersistentObjectConverter', \TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED, true);
                    $propertyMappingConfiguration->setTypeConverterOption('TYPO3\\Flow\\Property\\TypeConverter\\PersistentObjectConverter', \TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED, true);
                    return $this->propertyMapper->convert($rawValue, $propertyType, $propertyMappingConfiguration);
                } else {
                    return $rawValue;
                }
        }
    }

Usage Example

Example #1
0
 /**
  * Applies this change
  *
  * @return void
  */
 public function apply()
 {
     if ($this->canApply()) {
         $node = $this->getSubject();
         $value = $this->nodePropertyConversionService->convert($node->getNodeType(), $this->getPropertyName(), $this->getValue(), $node->getContext());
         $node->setProperty($this->getPropertyName(), $value);
         $this->updateWorkspaceInfo();
     }
 }
All Usage Examples Of Neos\Neos\Ui\Domain\Service\NodePropertyConversionService::convert