public function canAddChildNode($childNodeName, $nodeTypeName = null, $throw = false)
{
$childDefs = $this->getChildNodeDefinitions();
if ($nodeTypeName) {
try {
$nodeType = $this->nodeTypeManager->getNodeType($nodeTypeName);
if ($nodeType->isMixin() || $nodeType->isAbstract()) {
if ($throw) {
if ($nodeType->isMixin()) {
$errorMsg = "Can't add the child node '{$childNodeName}' for node type '{$nodeTypeName}' because the node type is mixin.";
} else {
$errorMsg = "Can't add the child node '{$childNodeName} for node type '{$nodeTypeName}' because the node type is abstract.";
}
throw new ConstraintViolationException($errorMsg);
}
return false;
}
} catch (NoSuchNodeTypeException $nsnte) {
if ($throw) {
throw $nsnte;
}
return false;
} catch (Exception $e) {
if ($throw) {
$errorMsg = "Can't add the child node '{$childNodeName}' for node type '{$nodeTypeName}' because of an Exception: " . $e->getMessage();
throw new ConstraintViolationException($errorMsg, null, $e);
}
return false;
}
}
foreach ($childDefs as $child) {
if ('*' === $child->getName() || $childNodeName === $child->getName()) {
if ($nodeTypeName === null) {
if ($child->getDefaultPrimaryTypeName() != null) {
return true;
}
} else {
foreach ($child->getRequiredPrimaryTypeNames() as $type) {
if ($nodeType->isNodeType($type)) {
return true;
}
}
}
}
}
if ($throw) {
$errorMsg = "Can't add the child node '{$childNodeName}' for node type '{$nodeTypeName}' because there is no definition for a child with that name.";
throw new ConstraintViolationException($errorMsg);
}
return false;
}