diff --git a/Neos.ContentRepository/Classes/Domain/Model/Node.php b/Neos.ContentRepository/Classes/Domain/Model/Node.php index a19a9170483..c7cdf56b2b7 100644 --- a/Neos.ContentRepository/Classes/Domain/Model/Node.php +++ b/Neos.ContentRepository/Classes/Domain/Model/Node.php @@ -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; } /** diff --git a/Neos.ContentRepository/Tests/Functional/Domain/NodesTest.php b/Neos.ContentRepository/Tests/Functional/Domain/NodesTest.php index cceb456f964..8c7d3288e85 100644 --- a/Neos.ContentRepository/Tests/Functional/Domain/NodesTest.php +++ b/Neos.ContentRepository/Tests/Functional/Domain/NodesTest.php @@ -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 */