/** * Creates a new node beneath $parent * * @param NodeInterface $parent * @return NodeInterface */ protected function createNode(NodeInterface $parent) { $nodeType = $this->getNodeType(); $name = $this->getName() ?: $this->nodeService->generateUniqueNodeName($parent->getPath()); $node = $parent->createNode($name, $nodeType); $this->applyNodeCreationHandlers($node); $this->persistenceManager->persistAll(); if ($nodeType->isOfType('TYPO3.Neos:Content') && ($this->getParentDomAddress() || $this->getSiblingDomAddress())) { if ($parent->getNodeType()->isOfType('TYPO3.Neos:ContentCollection')) { $renderContentOutOfBand = new RenderContentOutOfBand(); $renderContentOutOfBand->setNode($node); $renderContentOutOfBand->setParentDomAddress($this->getParentDomAddress()); $renderContentOutOfBand->setSiblingDomAddress($this->getSiblingDomAddress()); $renderContentOutOfBand->setMode($this->getMode()); $this->feedbackCollection->add($renderContentOutOfBand); } else { $flowQuery = new FlowQuery(array($node)); $closestDocument = $flowQuery->closest('[instanceof TYPO3.Neos:Document]')->get(0); $reloadDocument = new ReloadDocument(); $reloadDocument->setDocument($closestDocument); $this->feedbackCollection->add($reloadDocument); } } $updateNodeInfo = new UpdateNodeInfo(); $updateNodeInfo->setNode($node); $this->feedbackCollection->add($updateNodeInfo); return $node; }
/** * Copy $node before, into or after $targetNode * * @param NodeInterface $node the node to be copied * @param NodeInterface $targetNode the target node to be copied "to", see $position * @param string $position where the node should be added in relation to $targetNode (allowed: before, into, after) * @param string $nodeName optional node name (if empty random node name will be generated) * @return NodeInterface The copied node * @throws NodeException */ public function copy(NodeInterface $node, NodeInterface $targetNode, $position, $nodeName = null) { if (!in_array($position, array('before', 'into', 'after'), true)) { throw new NodeException('The position should be one of the following: "before", "into", "after".', 1346832303); } $nodeName = $this->nodeService->generateUniqueNodeName($this->getDesignatedParentNode($targetNode, $position)->getPath(), !empty($nodeName) ? $nodeName : null); switch ($position) { case 'before': $copiedNode = $node->copyBefore($targetNode, $nodeName); break; case 'after': $copiedNode = $node->copyAfter($targetNode, $nodeName); break; case 'into': default: $copiedNode = $node->copyInto($targetNode, $nodeName); } return $copiedNode; }
/** * Creates a new node beneath $parent * * @param NodeInterface $parent * @return NodeInterface */ protected function createNode(NodeInterface $parent) { $nodeType = $this->getNodeType(); $initialProperties = $this->getInitialProperties(); $name = $this->getName() ?: $this->nodeService->generateUniqueNodeName($parent->getPath()); // // If we're about to create a document, check for the presence of the uriPathSegment property first // and create it, if it's missing // if ($nodeType->isOfType('TYPO3.Neos:Document') && !isset($initialProperties['uriPathSegment'])) { if (!isset($initialProperties['title'])) { throw new \IllegalArgumentException('You must either provide a title or a uriPathSegment in order to create a document.', 1452103891); } $initialProperties['uriPathSegment'] = NodeUtility::renderValidNodeName($initialProperties['title']); } $node = $parent->createNode($name, $nodeType); foreach ($initialProperties as $key => $value) { $node->setProperty($key, $value); } return $node; }
/** * Creates and persists a node from the given $nodeTemplate as child node * * @param \TYPO3\TYPO3CR\Domain\Model\NodeTemplate $nodeTemplate * @param string $nodeName name of the new node. If not specified the name of the nodeTemplate will be used. * @param \TYPO3\TYPO3CR\Domain\Model\Workspace $workspace * @param array $dimensions * @return \TYPO3\TYPO3CR\Domain\Model\NodeData the freshly generated node */ public function createNodeDataFromTemplate(NodeTemplate $nodeTemplate, $nodeName = null, Workspace $workspace = null, array $dimensions = null) { $newNodeName = $nodeName !== null ? $nodeName : $nodeTemplate->getName(); $possibleNodeName = $this->nodeService->generateUniqueNodeName($this->getPath(), $newNodeName); $newNodeData = $this->createNodeData($possibleNodeName, $nodeTemplate->getNodeType(), $nodeTemplate->getIdentifier(), $workspace, $dimensions); $newNodeData->similarize($nodeTemplate); return $newNodeData; }