Skip to content

Commit

Permalink
Merge pull request #4480 from neos/task/4477-NodeType-getPropertyType…
Browse files Browse the repository at this point in the history
…-nullable

!!! TASK Make NodeType::getPropertyType throw
  • Loading branch information
ahaeslich authored Nov 2, 2023
2 parents e51bc6d + 2f1316a commit 3c97184
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
22 changes: 20 additions & 2 deletions Neos.ContentRepository.Core/Classes/NodeType/NodeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,31 @@ 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 (!$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'] ?? 'string';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down

0 comments on commit 3c97184

Please sign in to comment.