public nearestContentCollection ( Neos\ContentRepository\Domain\Model\NodeInterface $node, string $nodePath ) : Neos\ContentRepository\Domain\Model\NodeInterface | ||
$node | Neos\ContentRepository\Domain\Model\NodeInterface | |
$nodePath | string | |
return | Neos\ContentRepository\Domain\Model\NodeInterface |
public function nearestContentCollection(NodeInterface $node, $nodePath)
{
$contentCollectionType = 'Neos.Neos:ContentCollection';
if ($node->getNodeType()->isOfType($contentCollectionType)) {
return $node;
} else {
if ((string) $nodePath === '') {
throw new Exception(sprintf('No content collection of type %s could be found in the current node and no node path was provided. You might want to configure the nodePath property with a relative path to the content collection.', $contentCollectionType), 1409300545);
}
$subNode = $node->getNode($nodePath);
if ($subNode !== null && $subNode->getNodeType()->isOfType($contentCollectionType)) {
return $subNode;
} else {
throw new Exception(sprintf('No content collection of type %s could be found in the current node (%s) or at the path "%s". You might want to adjust your node type configuration and create the missing child node through the "flow node:repair --node-type %s" command.', $contentCollectionType, $node->getPath(), $nodePath, (string) $node->getNodeType()), 1389352984);
}
}
}