Skip to content

Commit

Permalink
BUGFIX: Removed super types can be added again regardless of order
Browse files Browse the repository at this point in the history
  • Loading branch information
ComiR committed Nov 13, 2018
1 parent 7d2cbf1 commit a8076ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 36 deletions.
42 changes: 11 additions & 31 deletions Neos.ContentRepository/Classes/Domain/Model/NodeType.php
Expand Up @@ -158,7 +158,7 @@ protected function initialize()
protected function buildFullConfiguration()
{
$mergedConfiguration = [];
$applicableSuperTypes = $this->buildInheritanceChain();
$applicableSuperTypes = static::getFlattenedSuperTypes($this);
foreach ($applicableSuperTypes as $key => $superType) {
$mergedConfiguration = Arrays::arrayMergeRecursiveOverrule($mergedConfiguration, $superType->getLocalConfiguration());
}
Expand All @@ -173,47 +173,27 @@ protected function buildFullConfiguration()
/**
* Returns a flat list of super types to inherit from.
*
* @param NodeType $nodeType
*
* @return array
*/
protected function buildInheritanceChain()
protected static function getFlattenedSuperTypes(NodeType $nodeType) : array
{
$superTypes = [];
foreach ($this->declaredSuperTypes as $superTypeName => $superType) {
$flattenedSuperTypes = [];
foreach ($nodeType->declaredSuperTypes as $superTypeName => $superType) {
if ($superType !== null) {
$this->addInheritedSuperTypes($superTypes, $superType);
$superTypes[$superTypeName] = $superType;
$flattenedSuperTypes += static::getFlattenedSuperTypes($superType);
$flattenedSuperTypes[$superTypeName] = $superType;
}
}

foreach ($this->declaredSuperTypes as $superTypeName => $superType) {
foreach ($nodeType->declaredSuperTypes as $superTypeName => $superType) {
if ($superType === null) {
unset($superTypes[$superTypeName]);
unset($flattenedSuperTypes[$superTypeName]);
}
}

return array_unique($superTypes);
}

/**
* Recursively add super types
*
* @param array $superTypes
* @param NodeType $superType
* @return void
*/
protected function addInheritedSuperTypes(array &$superTypes, NodeType $superType)
{
foreach ($superType->getDeclaredSuperTypes() as $inheritedSuperTypeName => $inheritedSuperType) {
$this->addInheritedSuperTypes($superTypes, $inheritedSuperType);
$superTypes[$inheritedSuperTypeName] = $inheritedSuperType;
}

$superTypesInSuperType = $superType->getConfiguration('superTypes') ?: [];
foreach ($superTypesInSuperType as $inheritedSuperTypeName => $inheritedSuperType) {
if (!$inheritedSuperType) {
unset($superTypes[$inheritedSuperTypeName]);
}
}
return $flattenedSuperTypes;
}

/**
Expand Down
11 changes: 6 additions & 5 deletions Neos.ContentRepository/Tests/Unit/Domain/Model/NodeTypeTest.php
Expand Up @@ -105,8 +105,9 @@ class NodeTypeTest extends UnitTestCase
],
'Neos.ContentRepository.Testing:SubSubShortcut' => [
'superTypes' => [
// SomeMixin placed explicitly before SubShortcut
'Neos.ContentRepository.Testing:SomeMixin' => true,
'Neos.ContentRepository.Testing:SubShortcut' => true,
'Neos.ContentRepository.Testing:SomeMixin' => true
],
'ui' => [
'label' => 'Sub-Sub-Shortcut'
Expand Down Expand Up @@ -411,13 +412,13 @@ public function superTypesRemovedByInheritanceCanBeAddedAgain()
$this->assertSame('Sub-Sub-Sub-Shortcut', $nodeType->getLabel());

$expectedProperties = [
'target' => [
'type' => 'string'
],
'someMixinProperty' => [
'type' => 'string',
'label' => 'Important hint'
]
],
'target' => [
'type' => 'string'
],
];
$this->assertSame($expectedProperties, $nodeType->getProperties());
}
Expand Down

0 comments on commit a8076ae

Please sign in to comment.