Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: NodeType allow unsetting inherited properties #4618

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Neos.ContentRepository.Core/Classes/NodeType/NodeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ protected function buildFullConfiguration(): array
}
$this->fullConfiguration = Arrays::arrayMergeRecursiveOverrule($mergedConfiguration, $this->localConfiguration);

// Remove unset properties
$this->fullConfiguration['properties'] = array_filter($this->fullConfiguration['properties'] ?? [], function ($propertyConfiguration) {
return $propertyConfiguration !== null;
});

if (
isset($this->fullConfiguration['childNodes'])
&& is_array($this->fullConfiguration['childNodes'])
Expand Down
14 changes: 0 additions & 14 deletions Neos.ContentRepository.Core/Classes/NodeType/NodeTypeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,6 @@ protected function loadNodeType(string $nodeTypeName, array &$completeNodeTypeCo
);
}

// Remove unset properties
$properties = [];
if (isset($nodeTypeConfiguration['properties']) && is_array($nodeTypeConfiguration['properties'])) {
$properties = $nodeTypeConfiguration['properties'];
}

$nodeTypeConfiguration['properties'] = array_filter($properties, function ($propertyConfiguration) {
return $propertyConfiguration !== null;
});

if ($nodeTypeConfiguration['properties'] === []) {
unset($nodeTypeConfiguration['properties']);
}

$nodeType = new NodeType(
NodeTypeName::fromString($nodeTypeName),
$superTypes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ public function arraySupertypesFormatThrowsException()
$this->expectException(NodeConfigurationException::class);
$nodeTypesFixture = [
'Neos.ContentRepository.Testing:Base' => [
'final' => true
],
'Neos.ContentRepository.Testing:Sub' => [
'superTypes' => [0 => 'Neos.ContentRepository.Testing:Base']
Expand All @@ -335,4 +334,92 @@ public function getSubNodeTypesWithDifferentIncludeFlagValuesReturnsCorrectValue
$subNodeTypes = $this->nodeTypeManager->getSubNodeTypes('Neos.ContentRepository.Testing:ContentObject', false);
self::assertArrayNotHasKey('Neos.ContentRepository.Testing:AbstractType', $subNodeTypes);
}

/**
* @test
*/
public function anInheritedNodeTypePropertyCanBeUnset(): void
{
$nodeTypesFixture = [
'Neos.ContentRepository.Testing:Base' => [
'properties' => [
'foo' => [
'type' => 'boolean',
]
]
],
'Neos.ContentRepository.Testing:Sub' => [
'superTypes' => ['Neos.ContentRepository.Testing:Base' => true],
'properties' => [
'foo' => null
]
]
];

$this->prepareNodeTypeManager($nodeTypesFixture);
$nodeType = $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:Sub');

self::assertSame([], $nodeType->getProperties());
}

/**
* @test
*/
public function allInheritedNodeTypePropertiesCanBeUnset(): void
{
$nodeTypesFixture = [
'Neos.ContentRepository.Testing:Base' => [
'properties' => [
'foo' => [
'type' => 'boolean',
]
]
],
'Neos.ContentRepository.Testing:Sub' => [
'superTypes' => ['Neos.ContentRepository.Testing:Base' => true],
'properties' => null
]
];

$this->prepareNodeTypeManager($nodeTypesFixture);
$nodeType = $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:Sub');

self::assertSame([], $nodeType->getProperties());
}

/**
* @test
*/
public function anInheritedNodeTypePropertyCannotBeSetToEmptyArray(): void
{
$nodeTypesFixture = [
'Neos.ContentRepository.Testing:Base' => [
'properties' => [
'foo' => [
'type' => 'boolean',
'ui' => [
'inspector' => [
'group' => 'things'
]
]
]
]
],
'Neos.ContentRepository.Testing:Sub' => [
'superTypes' => ['Neos.ContentRepository.Testing:Base' => true],
'properties' => [
// Pseudo unset.
// The property will still be existent but looses its type information (falls back to string).
// Also, the property will not show up anymore in the ui as the inspector configuration is gone as well.
'foo' => []
]
]
];

$this->prepareNodeTypeManager($nodeTypesFixture);
$nodeType = $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:Sub');

self::assertSame(['foo' => []], $nodeType->getProperties());
self::assertSame('string', $nodeType->getPropertyType('foo'));
}
}
Loading