Skip to content

Commit

Permalink
TASK: Prepare CreationDialogPostprocessor to be more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Mar 1, 2024
1 parent 9ed7d60 commit 8ca3440
Showing 1 changed file with 46 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string,mixed>
* @var array<string,mixed>
* @Flow\InjectConfiguration(package="Neos.Neos", path="userInterface.inspector.dataTypes")
*/
protected $dataTypesDefaultConfiguration;

/**
* @var array
* @phpstan-var array<string,mixed>
* @var array<string,mixed>
* @Flow\InjectConfiguration(package="Neos.Neos", path="userInterface.inspector.editors")
*/
protected $editorDefaultConfiguration;
Expand All @@ -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;
}

/**
Expand All @@ -110,7 +120,7 @@ public function process(NodeType $nodeType, array &$configuration, array $option
* @param array<string,mixed> $propertyConfiguration
* @return array<string,mixed>
*/
private function convertPropertyConfiguration(string $propertyName, array $propertyConfiguration): array
private function promotePropertyIntoCreationDialog(string $propertyName, array $propertyConfiguration): array
{
$dataType = $propertyConfiguration['type'] ?? 'string';
$dataTypeDefaultConfiguration = $this->dataTypesDefaultConfiguration[$dataType] ?? [];
Expand Down

0 comments on commit 8ca3440

Please sign in to comment.