Skip to content

Commit

Permalink
TASK: Introduce internal NodeTypeManager::requireNodeType
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Mar 18, 2024
1 parent b94a093 commit 1fcdec4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function createEventsForMissingTetheredNode(

if (count($childNodeAggregates) === 0) {
// there is no tethered child node aggregate already; let's create it!
$nodeType = $this->nodeTypeManager->getNodeType($parentNodeAggregate->nodeTypeName);
$nodeType = $this->nodeTypeManager->requireNodeType($parentNodeAggregate->nodeTypeName);
if ($nodeType->isOfType(NodeTypeName::ROOT_NODE_TYPE_NAME)) {
$events = [];
$tetheredNodeAggregateId = $tetheredNodeAggregateId ?: NodeAggregateId::create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private static function createNodeAggregateIdsForNodeType(
?string $pathPrefix = null
): array {
$nodeAggregateIds = [];
foreach ($nodeTypeManager->getTetheredNodesConfigurationForNodeType($nodeTypeManager->getNodeType($nodeTypeName)) as $nodeName => $childNodeType) {
foreach ($nodeTypeManager->getTetheredNodesConfigurationForNodeType($nodeTypeManager->requireNodeType($nodeTypeName)) as $nodeName => $childNodeType) {
$path = $pathPrefix ? $pathPrefix . '/' . $nodeName : $nodeName;
$nodeAggregateIds[$path] = NodeAggregateId::create();
$nodeAggregateIds = array_merge(
Expand Down
27 changes: 16 additions & 11 deletions Neos.ContentRepository.Core/Classes/NodeType/NodeTypeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,6 @@ public function getNodeType(string|NodeTypeName $nodeTypeName): ?NodeType
return null;
}

throw new NodeTypeNotFoundException(
sprintf(
'The node type "%s" is not available',
$nodeTypeName
),
1316598370
);
}

/**
* Checks if the specified node type exists
*
Expand Down Expand Up @@ -209,7 +200,7 @@ public function overrideNodeTypes(array $completeNodeTypeConfiguration): void
public function getTypeOfTetheredNode(NodeType $nodeType, NodeName $tetheredNodeName): NodeType
{
$nameOfTetheredNode = $nodeType->getNodeTypeNameOfTetheredNode($tetheredNodeName);
return $this->getNodeType($nameOfTetheredNode);
return $this->requireNodeType($nameOfTetheredNode);
}

/**
Expand All @@ -223,7 +214,7 @@ public function getTetheredNodesConfigurationForNodeType(NodeType $nodeType): ar
$autoCreatedChildNodes = [];
foreach ($childNodeConfiguration ?? [] as $childNodeName => $configurationForChildNode) {
if (isset($configurationForChildNode['type'])) {
$autoCreatedChildNodes[NodeName::transliterateFromString($childNodeName)->value] = $this->getNodeType($configurationForChildNode['type']);
$autoCreatedChildNodes[NodeName::transliterateFromString($childNodeName)->value] = $this->requireNodeType($configurationForChildNode['type']);
}
}
return $autoCreatedChildNodes;
Expand Down Expand Up @@ -389,4 +380,18 @@ private function evaluateSuperTypeConfiguration(

return $superType;
}

/**
* @internal helper to throw if the NodeType doesn't exit
*/
public function requireNodeType(string|NodeTypeName $nodeTypeName): NodeType
{
return $this->getNodeType($nodeTypeName) ?? throw new NodeTypeNotFoundException(
sprintf(
'The node type "%s" is not available',
$nodeTypeName instanceof NodeTypeName ? $nodeTypeName->value : $nodeTypeName
),
1316598370
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private function createVariantRecursivelyInternal(int $level, NodeAggregateId $p
foreach ($childNodes as $childNode) {
if ($childNode->classification->isRegular()) {
$childNodeType = $contentRepository->getNodeTypeManager()->getNodeType($childNode->nodeTypeName);
if ($childNodeType->isOfType('Neos.Neos:Document')) {
if ($childNodeType?->isOfType('Neos.Neos:Document')) {
$this->output("%s- %s\n", [
str_repeat(' ', $level),
$childNode->getProperty('uriPathSegment') ?? $childNode->nodeAggregateId->value
Expand Down

0 comments on commit 1fcdec4

Please sign in to comment.