public function createNode($name, NodeType $nodeType = null, $identifier = null)
{
$this->emitBeforeNodeCreate($this, $name, $nodeType, $identifier);
$newNode = $this->createSingleNode($name, $nodeType, $identifier);
if ($nodeType !== null) {
foreach ($nodeType->getDefaultValuesForProperties() as $propertyName => $propertyValue) {
if (substr($propertyName, 0, 1) === '_') {
ObjectAccess::setProperty($newNode, substr($propertyName, 1), $propertyValue);
} else {
$newNode->setProperty($propertyName, $propertyValue);
}
}
foreach ($nodeType->getAutoCreatedChildNodes() as $childNodeName => $childNodeType) {
$childNodeIdentifier = Utility::buildAutoCreatedChildNodeIdentifier($childNodeName, $newNode->getIdentifier());
$alreadyPresentChildNode = $newNode->getNode($childNodeName);
if ($alreadyPresentChildNode === null) {
$newNode->createNode($childNodeName, $childNodeType, $childNodeIdentifier);
}
}
}
$this->context->getFirstLevelNodeCache()->flush();
$this->emitNodeAdded($newNode);
$this->emitAfterNodeCreate($newNode);
return $newNode;
}