neos / neos-development-collection

The unified repository containing the Neos core packages, used for Neos development.
https://www.neos.io/
GNU General Public License v3.0
260 stars 221 forks source link

9.0 replacement for `Node::isNodeTypeAllowedAsChildNode`? #5062

Open mhsdesign opened 4 months ago

mhsdesign commented 4 months ago

The Neos ui currently holds such logic

protected function isNodeTypeAllowedAsChildNode(Node $parentNode, NodeTypeName $nodeTypeNameToCheck): bool
{
    $nodeTypeManager = $this->contentRepositoryRegistry->get($parentNode->contentRepositoryId)->getNodeTypeManager();

    $parentNodeType = $nodeTypeManager->getNodeType($parentNode->nodeTypeName);
    if (!$parentNodeType) {
        return false;
    }

    if ($parentNode->classification !== NodeAggregateClassification::CLASSIFICATION_TETHERED) {
        $nodeTypeToCheck = $nodeTypeManager->getNodeType($nodeTypeNameToCheck);
        if (!$nodeTypeToCheck) {
            return false;
        }
        return $parentNodeType->allowsChildNodeType($nodeTypeToCheck);
    }

    $subgraph = $this->contentRepositoryRegistry->subgraphForNode($parentNode);
    $grandParentNode = $subgraph->findParentNode($parentNode->aggregateId);

    return !$grandParentNode || $nodeTypeManager->isNodeTypeAllowedAsChildToTetheredNode(
        $grandParentNode->nodeTypeName,
        $parentNode->name,
        $nodeTypeNameToCheck
    );
}

that was once part of the Node itself via https://github.com/neos/neos-development-collection/blob/eada1dbfb569de6e3932b26b4b3c630401020e05/Neos.ContentRepository/Classes/Domain/Model/Node.php#L1927

That cannot be anymore as we removed the NodeType on the node but there should probably be a utility method?