Skip to content

Commit

Permalink
Merge pull request #4731 from mhsdesign/bugfix/nodeGetPropertyReturns…
Browse files Browse the repository at this point in the history
…ArrayWithHolesForReferences

BUGFIX: #3624 Node::getProperty does not always return list for references
  • Loading branch information
mhsdesign authored Jan 31, 2024
2 parents e62bd1e + 858a500 commit 0a30a0f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Neos.ContentRepository/Classes/Domain/Model/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -960,11 +960,15 @@ public function getProperty($propertyName, bool $returnNodesAsIdentifiers = fals
*/
protected function resolvePropertyReferences(array $value = []): array
{
$nodes = array_map(function ($nodeIdentifier) {
return $this->context->getNodeByIdentifier($nodeIdentifier);
}, $value);

return array_filter($nodes);
$nodes = [];
foreach ($value as $nodeIdentifier) {
$node = $this->context->getNodeByIdentifier($nodeIdentifier);
// $node can be NULL if the node is not visible (or removed) according to the current content context:
if ($node !== null) {
$nodes[] = $node;
}
}
return $nodes;
}

/**
Expand Down
28 changes: 28 additions & 0 deletions Neos.ContentRepository/Tests/Functional/Domain/NodesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,34 @@ public function getPropertyReturnsReferencedNodesInCorrectWorkspace()
self::assertSame($testReferencedNodeProperty->getWorkspace(), $testReferencedNode->getWorkspace());
}

/**
* @see https://github.com/neos/neos-development-collection/issues/3624
* @test
*/
public function getPropertyReturnsReferencedNodesWithoutHolesInArrayKeys(): void
{
$nodeTypeManager = $this->objectManager->get(NodeTypeManager::class);
$nodeType = $nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:NodeTypeWithReferences');

$rootNode = $this->context->getNode('/');
$nodeA = $rootNode->createNode('node-a', $nodeType, '30e893c1-caef-0ca5-b53d-e5699bb8e506');
$nodeB = $rootNode->createNode('node-b', $nodeType, '81c848ed-abb5-7608-a5db-7eea0331ccfa');
$nodeC = $rootNode->createNode('node-c', $nodeType, 'e3b99700-f632-4a4c-2f93-0ad07eaf733f');

$expectedNodes = [0 => $nodeB, 1 => $nodeC];

$nodeA->setProperty('property2', '81c848ed-abb5-7608-a5db-7eea0331ccfa');
$nodeA->setProperty('property3', [
'00000000-0000-0000-0000-000000000001',
'81c848ed-abb5-7608-a5db-7eea0331ccfa',
'00000000-0000-0000-0000-000000000002',
'e3b99700-f632-4a4c-2f93-0ad07eaf733f'
]);

$actualProperties = $nodeA->getProperties();
self::assertSame($expectedNodes, $actualProperties['property3']);
}

/**
* @test
*/
Expand Down

0 comments on commit 0a30a0f

Please sign in to comment.