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

BUGFIX: #3624 Node::getProperty does not always return list for references #4731

Merged
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
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;
mhsdesign marked this conversation as resolved.
Show resolved Hide resolved
}

/**
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 @@ -1412,6 +1412,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
Loading