diff --git a/Classes/NodeCreationHandler.php b/Classes/NodeCreationHandler.php index 85c5f2a..a14b943 100644 --- a/Classes/NodeCreationHandler.php +++ b/Classes/NodeCreationHandler.php @@ -2,7 +2,11 @@ namespace Wwwision\Neos\CreationDialogProperties; use Neos\ContentRepository\Domain\Model\NodeInterface; +use Neos\Flow\Annotations as Flow; +use Neos\Flow\Property\PropertyMapper; +use Neos\Flow\Property\TypeConverter\PersistentObjectConverter; use Neos\Neos\Ui\NodeCreationHandler\NodeCreationHandlerInterface; +use Neos\Utility\TypeHandling; /** * A Node Creation Handler that takes the incoming data from the Creation Dialog and sets the corresponding node property @@ -10,6 +14,12 @@ class NodeCreationHandler implements NodeCreationHandlerInterface { + /** + * @Flow\Inject + * @var PropertyMapper + */ + protected $propertyMapper; + /** * @param NodeInterface $node The newly created node * @param array $data incoming data from the creationDialog @@ -17,8 +27,17 @@ class NodeCreationHandler implements NodeCreationHandlerInterface */ public function handle(NodeInterface $node, array $data) { + $propertyMappingConfiguration = $this->propertyMapper->buildPropertyMappingConfiguration(); + $propertyMappingConfiguration->forProperty('*')->allowAllProperties(); + $propertyMappingConfiguration->setTypeConverterOption(PersistentObjectConverter::class, PersistentObjectConverter::CONFIGURATION_OVERRIDE_TARGET_TYPE_ALLOWED, true); + foreach ($data as $propertyName => $propertyValue) { + $propertyType = TypeHandling::normalizeType($node->getNodeType()->getPropertyType($propertyName)); + if ($propertyType !== 'references' && $propertyType !== 'reference' && $propertyType !== TypeHandling::getTypeForValue($propertyValue)) { + $propertyValue = $this->propertyMapper->convert($propertyValue, $propertyType, $propertyMappingConfiguration); + } $node->setProperty($propertyName, $propertyValue); + } } }