protected function createRecursiveCopy(NodeInterface $referenceNode, $nodeName, $detachedCopy)
{
$identifier = null;
$referenceNodeDimensions = $referenceNode->getDimensions();
$referenceNodeDimensionsHash = Utility::sortDimensionValueArrayAndReturnDimensionsHash($referenceNodeDimensions);
$thisDimensions = $this->getDimensions();
$thisNodeDimensionsHash = Utility::sortDimensionValueArrayAndReturnDimensionsHash($thisDimensions);
if ($detachedCopy === false && $referenceNodeDimensionsHash !== $thisNodeDimensionsHash && $referenceNode->getContext()->getNodeByIdentifier($this->getIdentifier()) === null) {
// If the target dimensions are different than this one, and there is no node shadowing this one in the target dimension yet, we use the same
// node identifier, effectively creating a new node variant.
$identifier = $this->getIdentifier();
}
$copiedNode = $referenceNode->createSingleNode($nodeName, null, $identifier);
$copiedNode->similarize($this, true);
/** @var $childNode Node */
foreach ($this->getChildNodes() as $childNode) {
// Prevent recursive copy when copying into itself
if ($childNode->getIdentifier() !== $copiedNode->getIdentifier()) {
$childNode->copyIntoInternal($copiedNode, $childNode->getName(), $detachedCopy);
}
}
return $copiedNode;
}