Skip to content

Commit

Permalink
Rename methods to use tethered instead of child node
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsunet committed Oct 13, 2023
1 parent 56e1b32 commit a2a0447
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ protected function requireRootNodeTypeToBeUnoccupied(
protected function requireTetheredDescendantNodeTypesToExist(NodeType $nodeType): void
{
// this getter throws if any of the child nodeTypes doesnt exist!
$childNodeTypes = $this->getNodeTypeManager()->getAutoCreatedChildNodesFor($nodeType);
foreach ($childNodeTypes as $childNodeType) {
$this->requireTetheredDescendantNodeTypesToExist($childNodeType);
$tetheredNodeTypes = $this->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($nodeType);
foreach ($tetheredNodeTypes as $tetheredNodeType) {
$this->requireTetheredDescendantNodeTypesToExist($tetheredNodeType);
}
}

Expand All @@ -176,7 +176,7 @@ protected function requireTetheredDescendantNodeTypesToExist(NodeType $nodeType)
*/
protected function requireTetheredDescendantNodeTypesToNotBeOfTypeRoot(NodeType $nodeType): void
{
foreach ($this->getNodeTypeManager()->getAutoCreatedChildNodesFor($nodeType) as $tetheredChildNodeType) {
foreach ($this->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($nodeType) as $tetheredChildNodeType) {
if ($tetheredChildNodeType->isOfType(NodeTypeName::ROOT_NODE_TYPE_NAME)) {
throw new NodeTypeIsOfTypeRoot(
'Node type "' . $nodeType->name->value . '" for tethered descendant is of type root.',
Expand Down Expand Up @@ -301,12 +301,12 @@ protected function requireNodeTypeConstraintsImposedByParentToBeMet(
}
if (
$nodeName
&& $parentsNodeType->hasAutoCreatedChildNode($nodeName)
&& !$this->getNodeTypeManager()->getTypeOfAutoCreatedChildNode($parentsNodeType, $nodeName)->name->equals($nodeType->name)
&& $parentsNodeType->hasTetheredNode($nodeName)
&& !$this->getNodeTypeManager()->getTypeOfTetheredNode($parentsNodeType, $nodeName)->name->equals($nodeType->name)
) {
throw new NodeConstraintException(
'Node type "' . $nodeType->name->value . '" does not match configured "'
. $this->getNodeTypeManager()->getTypeOfAutoCreatedChildNode($parentsNodeType, $nodeName)->name->value
. $this->getNodeTypeManager()->getTypeOfTetheredNode($parentsNodeType, $nodeName)->name->value
. '" for auto created child nodes for parent type "' . $parentsNodeType->name->value
. '" with name "' . $nodeName->value . '"'
);
Expand All @@ -324,8 +324,8 @@ protected function areNodeTypeConstraintsImposedByParentValid(
}
if (
$nodeName
&& $parentsNodeType->hasAutoCreatedChildNode($nodeName)
&& !$this->getNodeTypeManager()->getTypeOfAutoCreatedChildNode($parentsNodeType, $nodeName)->name->equals($nodeType->name)
&& $parentsNodeType->hasTetheredNode($nodeName)
&& !$this->getNodeTypeManager()->getTypeOfTetheredNode($parentsNodeType, $nodeName)->name->equals($nodeType->name)
) {
return false;
}
Expand Down Expand Up @@ -362,8 +362,8 @@ protected function areNodeTypeConstraintsImposedByGrandparentValid(
): bool {
if (
$parentNodeName
&& $grandParentsNodeType->hasAutoCreatedChildNode($parentNodeName)
&& !$this->getNodeTypeManager()->allowsGrandchildNodeType($grandParentsNodeType, $parentNodeName, $nodeType)
&& $grandParentsNodeType->hasTetheredNode($parentNodeName)
&& !$this->getNodeTypeManager()->isNodeTypeAllowedAsChildToTetheredNode($grandParentsNodeType, $parentNodeName, $nodeType)
) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ protected function checkConstraintsImposedByAncestors(
}
if (
$nodeAggregate->nodeName
&& $parentsNodeType->hasAutoCreatedChildNode($nodeAggregate->nodeName)
&& $this->nodeTypeManager->getTypeOfAutoCreatedChildNode($parentsNodeType, $nodeAggregate->nodeName)->name
&& $parentsNodeType->hasTetheredNode($nodeAggregate->nodeName)
&& $this->nodeTypeManager->getTypeOfTetheredNode($parentsNodeType, $nodeAggregate->nodeName)->name
!== $command->newNodeTypeName->value
) {
throw new NodeConstraintException(
Expand All @@ -232,8 +232,8 @@ protected function checkConstraintsImposedByAncestors(
);
if (
$parentAggregate->nodeName
&& $grandParentsNodeType->hasAutoCreatedChildNode($parentAggregate->nodeName)
&& !$this->nodeTypeManager->allowsGrandchildNodeType(
&& $grandParentsNodeType->hasTetheredNode($parentAggregate->nodeName)
&& !$this->nodeTypeManager->isNodeTypeAllowedAsChildToTetheredNode(
$grandParentsNodeType,
$parentAggregate->nodeName,
$newNodeType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ private function handleTetheredChildNodes(
ContentRepository $contentRepository,
): Events {
$events = [];
foreach ($this->getNodeTypeManager()->getAutoCreatedChildNodesFor($nodeType) as $rawNodeName => $childNodeType) {
foreach ($this->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($nodeType) as $rawNodeName => $childNodeType) {
assert($childNodeType instanceof NodeType);
$nodeName = NodeName::fromString($rawNodeName);
$childNodePath = $nodePath
Expand Down Expand Up @@ -355,7 +355,7 @@ protected static function populateNodeAggregateIds(
$nodeAggregateIds = NodeAggregateIdsByNodePaths::createEmpty();
}
// TODO: handle Multiple levels of autocreated child nodes
foreach ($nodeTypeManager->getAutoCreatedChildNodesFor($nodeType) as $rawChildName => $childNodeType) {
foreach ($nodeTypeManager->getTetheredNodesConfigurationForNodeType($nodeType) as $rawChildName => $childNodeType) {
$childName = NodeName::fromString($rawChildName);
$childPath = $childPath
? $childPath->appendPathSegment($childName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private function handleChangeNodeAggregateType(
}

// new tethered child nodes
$expectedTetheredNodes = $this->getNodeTypeManager()->getAutoCreatedChildNodesFor($newNodeType);
$expectedTetheredNodes = $this->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($newNodeType);
foreach ($nodeAggregate->getNodes() as $node) {
assert($node instanceof Node);
foreach ($expectedTetheredNodes as $serializedTetheredNodeName => $expectedTetheredNodeType) {
Expand Down Expand Up @@ -376,7 +376,7 @@ private function deleteObsoleteTetheredNodesWhenChangingNodeType(
NodeType $newNodeType,
ContentRepository $contentRepository
): Events {
$expectedTetheredNodes = $this->getNodeTypeManager()->getAutoCreatedChildNodesFor($newNodeType);
$expectedTetheredNodes = $this->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($newNodeType);

$events = [];
// find disallowed tethered nodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
/**
* @api Might be encountered when childNode information is requested for a child node which was never configured.
*/
class ChildNodeNotConfigured extends \DomainException
class TetheredNodeNotConfigured extends \DomainException
{
}
12 changes: 6 additions & 6 deletions Neos.ContentRepository.Core/Classes/NodeType/NodeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* source code.
*/

use Neos\ContentRepository\Core\NodeType\Exception\ChildNodeNotConfigured;
use Neos\ContentRepository\Core\NodeType\Exception\TetheredNodeNotConfigured;
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\Utility\ObjectAccess;
use Neos\Utility\Arrays;
Expand Down Expand Up @@ -438,7 +438,7 @@ public function getDefaultValuesForProperties(): array
/**
* @return bool true if $nodeName is an autocreated child node, false otherwise
*/
public function hasAutoCreatedChildNode(NodeName $nodeName): bool
public function hasTetheredNode(NodeName $nodeName): bool
{
$this->initialize();
foreach ($this->fullConfiguration['childNodes'] ?? [] as $rawChildNodeName => $configurationForChildNode) {
Expand All @@ -452,9 +452,9 @@ public function hasAutoCreatedChildNode(NodeName $nodeName): bool
}

/**
* @throws ChildNodeNotConfigured if the requested childNode is not configured. Check via {@see NodeType::hasAutoCreatedChildNode()}.
* @throws TetheredNodeNotConfigured if the requested tethred node is not configured. Check via {@see NodeType::hasTetheredNode()}.
*/
public function getNodeTypeNameOfAutoCreatedChildNode(NodeName $nodeName): NodeTypeName
public function getNodeTypeNameOfTetheredNode(NodeName $nodeName): NodeTypeName
{
$this->initialize();
foreach ($this->fullConfiguration['childNodes'] ?? [] as $rawChildNodeName => $configurationForChildNode) {
Expand All @@ -464,15 +464,15 @@ public function getNodeTypeNameOfAutoCreatedChildNode(NodeName $nodeName): NodeT
}
}
}
throw new ChildNodeNotConfigured(sprintf('The child node "%s" is not configured for node type "%s"', $nodeName->value, $this->name->value), 1694786811);
throw new TetheredNodeNotConfigured(sprintf('The child node "%s" is not configured for node type "%s"', $nodeName->value, $this->name->value), 1694786811);
}

/**
* Checks if the given NodeType is acceptable as sub-node with the configured constraints,
* not taking constraints of auto-created nodes into account. Thus, this method only returns
* the correct result if called on NON-AUTO-CREATED nodes!
*
* Otherwise, allowsGrandchildNodeType() needs to be called on the *parent node type*.
* Otherwise, isNodeTypeAllowedAsChildToTetheredNode() needs to be called on the *parent node type*.
*
* @return boolean true if the $nodeType is allowed as child node, false otherwise.
*/
Expand Down
39 changes: 19 additions & 20 deletions Neos.ContentRepository.Core/Classes/NodeType/NodeTypeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Neos\ContentRepository\Core\NodeType;

use Neos\ContentRepository\Core\NodeType\Exception\ChildNodeNotConfigured;
use Neos\ContentRepository\Core\NodeType\Exception\TetheredNodeNotConfigured;
use Neos\ContentRepository\Core\SharedModel\Exception\NodeConfigurationException;
use Neos\ContentRepository\Core\SharedModel\Exception\NodeTypeIsFinalException;
use Neos\ContentRepository\Core\SharedModel\Exception\NodeTypeNotFoundException;
Expand Down Expand Up @@ -188,14 +188,14 @@ public function overrideNodeTypes(array $completeNodeTypeConfiguration): void

/**
* @param NodeType $nodeType
* @param NodeName $childNodeName
* @throws ChildNodeNotConfigured if the requested childNode is not configured. Check via {@see NodeType::hasAutoCreatedChildNode()}.
* @param NodeName $tetheredNodeName
* @return NodeType
*@throws TetheredNodeNotConfigured if the requested tethered node is not configured. Check via {@see NodeType::hasTetheredNode()}.
*/
public function getTypeOfAutoCreatedChildNode(NodeType $nodeType, NodeName $childNodeName): NodeType
public function getTypeOfTetheredNode(NodeType $nodeType, NodeName $tetheredNodeName): NodeType
{
$childNodeTypeName = $nodeType->getNodeTypeNameOfAutoCreatedChildNode($childNodeName);
return $this->getNodeType($childNodeTypeName);
$nameOfTetheredNode = $nodeType->getNodeTypeNameOfTetheredNode($tetheredNodeName);
return $this->getNodeType($nameOfTetheredNode);
}

/**
Expand All @@ -204,53 +204,52 @@ public function getTypeOfAutoCreatedChildNode(NodeType $nodeType, NodeName $chil
* @return array<string,NodeType> the key of this array is the name of the child, and the value its NodeType.
* @api
*/
public function getAutoCreatedChildNodesFor(NodeType $nodeType): array
public function getTetheredNodesConfigurationForNodeType(NodeType $nodeType): array
{
$childNodeConfiguration = $nodeType->getConfiguration('childNodes');
$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->getNodeType($configurationForChildNode['type']);
}
}
return $autoCreatedChildNodes;
}

/**
* Checks if the given $nodeType is allowed as a childNode of the given $childNodeName
* (which must be auto-created in $this NodeType).
* Checks if the given $nodeType is allowed as a childNode of the given $tetheredNodeName
* (which must be tethered in $parentNodeType).
*
* Only allowed to be called if $childNodeName is auto-created.
* Only allowed to be called if $tetheredNodeName is actually tethered.
*
* @param NodeType $parentNodeType The NodeType to check constraints based on.
* @param NodeName $childNodeName The name of a configured childNode of this NodeType
* @param NodeName $tetheredNodeName The name of a configured tethered node of this NodeType
* @param NodeType $nodeType The NodeType to check constraints for.
* @return bool true if the $nodeType is allowed as grandchild node, false otherwise.
* @throws \InvalidArgumentException if the requested childNode is not configured in the parent NodeType. Check via {@see NodeType::hasAutoCreatedChildNode()}.
* @throws \InvalidArgumentException if the requested tethered node is not configured in the parent NodeType. Check via {@see NodeType::hasTetheredNode()}.
*/
public function allowsGrandchildNodeType(NodeType $parentNodeType, NodeName $childNodeName, NodeType $nodeType): bool
public function isNodeTypeAllowedAsChildToTetheredNode(NodeType $parentNodeType, NodeName $tetheredNodeName, NodeType $nodeType): bool
{
try {
$childNodeType = $this->getTypeOfAutoCreatedChildNode($parentNodeType, $childNodeName);
} catch (ChildNodeNotConfigured $exception) {
$typeOfTetheredNode = $this->getTypeOfTetheredNode($parentNodeType, $tetheredNodeName);
} catch (TetheredNodeNotConfigured $exception) {
throw new \InvalidArgumentException(
sprintf(
'Cannot determine if grandchild is allowed in %s. Because the given child node name "%s" is not auto-created.',
$parentNodeType->name->value,
$childNodeName->value
$tetheredNodeName->value
),
1403858395,
$exception
);
}

// Constraints configured on the NodeType for the child node
$constraints = $childNodeType->getConfiguration('constraints.nodeTypes') ?: [];
$constraints = $typeOfTetheredNode->getConfiguration('constraints.nodeTypes') ?: [];

// Constraints configured at the childNode configuration of the parent.
try {
$childNodeConstraintConfiguration = $parentNodeType->getConfiguration('childNodes.' . $childNodeName->value . '.constraints.nodeTypes') ?? [];
$childNodeConstraintConfiguration = $parentNodeType->getConfiguration('childNodes.' . $tetheredNodeName->value . '.constraints.nodeTypes') ?? [];
} catch (PropertyNotAccessibleException $exception) {
// We ignore this because the configuration might just not have any constraints, if the childNode was not configured the exception above would have been thrown.
$childNodeConstraintConfiguration = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public function getSubNodeTypesWithDifferentIncludeFlagValuesReturnsCorrectValue
public function getAutoCreatedChildNodesReturnsLowercaseNames()
{
$parentNodeType = $this->nodeTypeManager->getNodeType(NodeTypeName::fromString('Neos.ContentRepository.Testing:Page2'));
$autoCreatedChildNodes = $this->nodeTypeManager->getAutoCreatedChildNodesFor($parentNodeType);
$autoCreatedChildNodes = $this->nodeTypeManager->getTetheredNodesConfigurationForNodeType($parentNodeType);
// This is configured as "nodeName" above, but should be normalized to "nodename"
self::assertArrayHasKey('nodename', $autoCreatedChildNodes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ private function isAutoCreatedChildNode(NodeTypeName $parentNodeTypeName, NodeNa
return false;
}
$nodeTypeOfParent = $this->nodeTypeManager->getNodeType($parentNodeTypeName);
return $nodeTypeOfParent->hasAutoCreatedChildNode($nodeName);
return $nodeTypeOfParent->hasTetheredNode($nodeName);
}

private function dispatch(Severity $severity, string $message, mixed ...$args): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function findAdjustmentsForNodeType(NodeTypeName $nodeTypeName): \Generat
) {
if ($this->nodeTypeManager->hasNodeType($grandparentNode->nodeTypeName)) {
if ($grandparentNodeType !== null) {
$allowedByGrandparent = $this->nodeTypeManager->allowsGrandchildNodeType(
$allowedByGrandparent = $this->nodeTypeManager->isNodeTypeAllowedAsChildToTetheredNode(
$grandparentNodeType,
$parentNode->nodeName,
$nodeType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function findAdjustmentsForNodeType(NodeTypeName $nodeTypeName): \Generat
// In case we cannot find the expected tethered nodes, this fix cannot do anything.
return;
}
$expectedTetheredNodes = $this->nodeTypeManager->getAutoCreatedChildNodesFor($nodeType);
$expectedTetheredNodes = $this->nodeTypeManager->getTetheredNodesConfigurationForNodeType($nodeType);

$expectedTetheredNodes = $nodeType->getAutoCreatedChildNodes();

Expand Down
4 changes: 2 additions & 2 deletions Neos.Neos/Classes/Service/NodeTypeSchemaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ protected function generateConstraints()
}
}

foreach ($this->nodeTypeManager->getAutoCreatedChildNodesFor($nodeType) as $key => $_x) {
foreach ($this->nodeTypeManager->getTetheredNodesConfigurationForNodeType($nodeType) as $key => $_x) {
foreach ($nodeTypes as $innerNodeTypeName => $innerNodeType) {
if ($this->nodeTypeManager->allowsGrandchildNodeType($nodeType, NodeName::fromString($key), $innerNodeType)) {
if ($this->nodeTypeManager->isNodeTypeAllowedAsChildToTetheredNode($nodeType, NodeName::fromString($key), $innerNodeType)) {
$constraints[$nodeTypeName]['childNodes'][$key]['nodeTypes'][$innerNodeTypeName] = true;
}
}
Expand Down

0 comments on commit a2a0447

Please sign in to comment.