Skip to content

Commit

Permalink
Merge pull request #3720 from kdambekalns/bugfix/3719-creation-dialog…
Browse files Browse the repository at this point in the history
…-property-conversion

BUGFIX Fix conversion in CreationDialogPropertiesCreationHandler
  • Loading branch information
mhsdesign authored Mar 16, 2024
2 parents cf41c70 + af67870 commit d0d8518
Showing 1 changed file with 8 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@

use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Property\Exception as PropertyException;
use Neos\Flow\Property\PropertyMapper;
use Neos\Flow\Property\TypeConverter\PersistentObjectConverter;
use Neos\Flow\Security\Exception as SecurityException;
use Neos\Neos\Ui\Domain\Service\NodePropertyConversionService;
use Neos\Neos\Ui\NodeCreationHandler\NodeCreationHandlerInterface;
use Neos\Utility\ObjectAccess;
use Neos\Utility\TypeHandling;

Expand All @@ -27,37 +25,22 @@ class CreationDialogPropertiesCreationHandler implements NodeCreationHandlerInte
{
/**
* @Flow\Inject
* @var PropertyMapper
* @var NodePropertyConversionService
*/
protected $propertyMapper;
protected $nodePropertyConversionService;

/**
* @param NodeInterface $node The newly created node
* @param array $data incoming data from the creationDialog
* @return void
* @throws PropertyException | SecurityException
*/
public function handle(NodeInterface $node, array $data): void
{
$propertyMappingConfiguration = $this->propertyMapper->buildPropertyMappingConfiguration();
$propertyMappingConfiguration->forProperty('*')->allowAllProperties();
$propertyMappingConfiguration->setTypeConverterOption(PersistentObjectConverter::class, PersistentObjectConverter::CONFIGURATION_OVERRIDE_TARGET_TYPE_ALLOWED, true);

foreach ($node->getNodeType()->getConfiguration('properties') as $propertyName => $propertyConfiguration) {
foreach ($data as $propertyName => $propertyValue) {
$propertyConfiguration = $node->getNodeType()->getConfiguration('properties')[$propertyName] ?? null;
if (!isset($propertyConfiguration['ui']['showInCreationDialog']) || $propertyConfiguration['ui']['showInCreationDialog'] !== true) {
continue;
}
$propertyType = TypeHandling::normalizeType($propertyConfiguration['type'] ?? 'string');
if (!isset($data[$propertyName])) {
if ($propertyValue === null || ($propertyValue === '' && !TypeHandling::isSimpleType($propertyType))) {
continue;
}
$propertyValue = $data[$propertyName];
if ($propertyValue === '' && !TypeHandling::isSimpleType($propertyType)) {
continue;
}
if ($propertyType !== 'references' && $propertyType !== 'reference' && $propertyType !== TypeHandling::getTypeForValue($propertyValue)) {
$propertyValue = $this->propertyMapper->convert($propertyValue, $propertyType, $propertyMappingConfiguration);
}
$propertyValue = $this->nodePropertyConversionService->convert($node->getNodeType(), $propertyName, $propertyValue, $node->getContext());
if (strncmp($propertyName, '_', 1) === 0) {
ObjectAccess::setProperty($node, substr($propertyName, 1), $propertyValue);
} else {
Expand Down

0 comments on commit d0d8518

Please sign in to comment.