From 8ca3440a69fc68dbd1b8efbe5157d82f0c3d62c3 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Fri, 1 Mar 2024 16:35:06 +0100 Subject: [PATCH] TASK: Prepare `CreationDialogPostprocessor` to be more generic --- .../CreationDialogNodeTypePostprocessor.php | 82 +++++++++++-------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/Classes/Infrastructure/ContentRepository/CreationDialog/CreationDialogNodeTypePostprocessor.php b/Classes/Infrastructure/ContentRepository/CreationDialog/CreationDialogNodeTypePostprocessor.php index e43b78cff0..9c7557bd97 100644 --- a/Classes/Infrastructure/ContentRepository/CreationDialog/CreationDialogNodeTypePostprocessor.php +++ b/Classes/Infrastructure/ContentRepository/CreationDialog/CreationDialogNodeTypePostprocessor.php @@ -21,50 +21,53 @@ use Neos\Utility\PositionalArraySorter; /** - * Node Type post processor that looks for properties flagged with "showInCreationDialog" + * NodeType post processor for the "ui.creationDialog" configuration: + * + * Promotes elements into creation dialog + * -------------------------------------- + * We look for properties flagged with "showInCreationDialog" * and sets the "creationDialog" configuration accordingly * * Example NodeTypes.yaml configuration: * - * 'Some.Node:Type': - * # ... - * properties: - * 'someProperty': - * type: string - * ui: - * label: 'Link' - * showInCreationDialog: true - * inspector: - * editor: 'Neos.Neos/Inspector/Editors/LinkEditor' - * - * Will be converted to: - * - * 'Some.Node:Type': - * # ... - * ui: - * creationDialog: - * elements: + * 'Some.Node:Type': + * # ... + * properties: * 'someProperty': * type: string * ui: * label: 'Link' - * editor: 'Neos.Neos/Inspector/Editors/LinkEditor' - * properties: - * 'someProperty': + * showInCreationDialog: true + * inspector: + * editor: 'Neos.Neos/Inspector/Editors/LinkEditor' + * + * Will be converted to: + * + * 'Some.Node:Type': * # ... + * ui: + * creationDialog: + * elements: + * 'someProperty': + * type: string + * ui: + * label: 'Link' + * editor: 'Neos.Neos/Inspector/Editors/LinkEditor' + * properties: + * 'someProperty': + * # ... + * */ class CreationDialogNodeTypePostprocessor implements NodeTypePostprocessorInterface { /** - * @var array - * @phpstan-var array + * @var array * @Flow\InjectConfiguration(package="Neos.Neos", path="userInterface.inspector.dataTypes") */ protected $dataTypesDefaultConfiguration; /** - * @var array - * @phpstan-var array + * @var array * @Flow\InjectConfiguration(package="Neos.Neos", path="userInterface.inspector.editors") */ protected $editorDefaultConfiguration; @@ -81,26 +84,33 @@ public function process(NodeType $nodeType, array &$configuration, array $option return; } $creationDialogElements = $configuration['ui']['creationDialog']['elements'] ?? []; - foreach ($configuration['properties'] as $propertyName => $propertyConfiguration) { + + $creationDialogElements = $this->promotePropertiesIntoCreationDialog($configuration['properties'], $creationDialogElements); + + if ($creationDialogElements !== []) { + $configuration['ui']['creationDialog']['elements'] = (new PositionalArraySorter($creationDialogElements))->toArray(); + } + } + + private function promotePropertiesIntoCreationDialog(array $properties, array $explicitCreationDialogElements): array + { + foreach ($properties as $propertyName => $propertyConfiguration) { if ( !isset($propertyConfiguration['ui']['showInCreationDialog']) || $propertyConfiguration['ui']['showInCreationDialog'] !== true ) { continue; } - $creationDialogElement = $this->convertPropertyConfiguration($propertyName, $propertyConfiguration); - if (isset($configuration['ui']['creationDialog']['elements'][$propertyName])) { + $creationDialogElement = $this->promotePropertyIntoCreationDialog($propertyName, $propertyConfiguration); + if (isset($explicitCreationDialogElements[$propertyName])) { $creationDialogElement = Arrays::arrayMergeRecursiveOverrule( $creationDialogElement, - $configuration['ui']['creationDialog']['elements'][$propertyName] + $explicitCreationDialogElements[$propertyName] ); } - $creationDialogElements[$propertyName] = $creationDialogElement; - } - if ($creationDialogElements !== []) { - $configuration['ui']['creationDialog']['elements'] - = (new PositionalArraySorter($creationDialogElements))->toArray(); + $explicitCreationDialogElements[$propertyName] = $creationDialogElement; } + return $explicitCreationDialogElements; } /** @@ -110,7 +120,7 @@ public function process(NodeType $nodeType, array &$configuration, array $option * @param array $propertyConfiguration * @return array */ - private function convertPropertyConfiguration(string $propertyName, array $propertyConfiguration): array + private function promotePropertyIntoCreationDialog(string $propertyName, array $propertyConfiguration): array { $dataType = $propertyConfiguration['type'] ?? 'string'; $dataTypeDefaultConfiguration = $this->dataTypesDefaultConfiguration[$dataType] ?? [];