From ac88f59aabc8c0abca27c5b270ad3f71c09ba0fe Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Mon, 18 Sep 2023 20:41:07 +0200 Subject: [PATCH 1/2] !!! TASK Make NodeType::getPropertyType throw if property not declared Resolves #4477 --- .../Classes/NodeType/NodeType.php | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Neos.ContentRepository.Core/Classes/NodeType/NodeType.php b/Neos.ContentRepository.Core/Classes/NodeType/NodeType.php index 91f4d254b78..337ba220878 100644 --- a/Neos.ContentRepository.Core/Classes/NodeType/NodeType.php +++ b/Neos.ContentRepository.Core/Classes/NodeType/NodeType.php @@ -409,22 +409,32 @@ public function getProperties(): array } /** - * Returns the configured type of the specified property + * Check if the property is configured in the schema. + */ + public function hasProperty(string $propertyName): bool + { + $this->initialize(); + + return isset($this->fullConfiguration['properties'][$propertyName]); + } + + /** + * Returns the configured type of the specified property, and falls back to 'string'. * - * @param string $propertyName Name of the property + * @throws \InvalidArgumentException if the property is not configured */ public function getPropertyType(string $propertyName): string { $this->initialize(); - if ( - !isset($this->fullConfiguration['properties']) - || !isset($this->fullConfiguration['properties'][$propertyName]) - || !isset($this->fullConfiguration['properties'][$propertyName]['type']) - ) { - return 'string'; + if (!$this->hasProperty($propertyName)) { + throw new \InvalidArgumentException( + sprintf('NodeType schema has no property "%s" configured. Cannot read its type.', $propertyName), + 1695062252040 + ); } - return $this->fullConfiguration['properties'][$propertyName]['type']; + + return $this->fullConfiguration['properties'][$propertyName]['type'] ?? 'string'; } /** From 55e1ebfd6825bc17902706a1a1cf7b24c6e80955 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sun, 24 Sep 2023 21:34:49 +0200 Subject: [PATCH 2/2] BUGFIX: Fix `${q(node).property("undefined")}` access. NodeType schema has no property "undefined" configured. Cannot read its type. --- .../Classes/FlowQueryOperations/PropertyOperation.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Neos.ContentRepository.NodeAccess/Classes/FlowQueryOperations/PropertyOperation.php b/Neos.ContentRepository.NodeAccess/Classes/FlowQueryOperations/PropertyOperation.php index 127a0244727..dc3701cdda4 100644 --- a/Neos.ContentRepository.NodeAccess/Classes/FlowQueryOperations/PropertyOperation.php +++ b/Neos.ContentRepository.NodeAccess/Classes/FlowQueryOperations/PropertyOperation.php @@ -110,7 +110,11 @@ public function evaluate(FlowQuery $flowQuery, array $arguments): mixed return ObjectAccess::getPropertyPath($element, substr($propertyName, 1)); } - if ($element->nodeType->getPropertyType($propertyName) === 'reference') { + $propertyType = $element->nodeType->hasProperty($propertyName) + ? $element->nodeType->getPropertyType($propertyName) + : null; + + if ($propertyType === 'reference') { $subgraph = $this->contentRepositoryRegistry->subgraphForNode($element); return ( $subgraph->findReferences( @@ -120,7 +124,7 @@ public function evaluate(FlowQuery $flowQuery, array $arguments): mixed )?->node; } - if ($element->nodeType->getPropertyType($propertyName) === 'references') { + if ($propertyType === 'references') { $subgraph = $this->contentRepositoryRegistry->subgraphForNode($element); return $subgraph->findReferences( $element->nodeAggregateId,