Neos\ContentRepository\Domain\Model\Node::createNode PHP Метод

createNode() публичный Метод

Creates, adds and returns a child node of this node. Also sets default properties and creates default subnodes.
public createNode ( string $name, NodeType $nodeType = null, string $identifier = null ) : Neos\ContentRepository\Domain\Model\NodeInterface
$name string Name of the new node
$nodeType NodeType Node type of the new node (optional)
$identifier string The identifier of the node, unique within the workspace, optional(!)
Результат Neos\ContentRepository\Domain\Model\NodeInterface
    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;
    }

Usage Example

 /**
  * @test
  */
 public function removedNodeWithoutExistingTargetNodeDataWillBeRemovedWhenPublished()
 {
     $homepageNode = $this->rootNode->createNode('homepage');
     $homepageNode->remove();
     $this->rootNode->getWorkspace()->publish($this->liveWorkspace);
     $this->saveNodesAndTearDownRootNodeAndRepository();
     $this->setUpRootNodeAndRepository();
     $liveContext = $this->contextFactory->create(array('workspaceName' => 'live', 'removedContentShown' => true));
     $liveRootNode = $liveContext->getRootNode();
     $liveHomepageNode = $liveRootNode->getNode('homepage');
     $this->assertTrue($liveHomepageNode === null, 'A removed node should be removed after publishing, but it was still found');
 }
All Usage Examples Of Neos\ContentRepository\Domain\Model\Node::createNode
Node