コード例 #1
0
 /**
  * Returns a node specified by the given relative path.
  *
  * @param string $path Path specifying the node, relative to this node
  * @return NodeInterface The specified node or NULL if no such node exists
  * @api
  */
 public function getNode($path)
 {
     $absolutePath = $this->nodeService->normalizePath($path, $this->getPath());
     $node = $this->context->getFirstLevelNodeCache()->getByPath($absolutePath);
     if ($node !== false) {
         return $node;
     }
     $node = $this->nodeDataRepository->findOneByPathInContext($absolutePath, $this->context);
     $this->context->getFirstLevelNodeCache()->setByPath($absolutePath, $node);
     return $node;
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
 /**
  * Converts the specified $source into a Node.
  *
  * If $source is a UUID it is expected to refer to the identifier of a NodeData record of the "live" workspace
  *
  * Otherwise $source has to be a valid node path:
  *
  * The node path must be an absolute context node path and can be specified as a string or as an array item with the
  * key "__contextNodePath". The latter case is for updating existing nodes.
  *
  * This conversion method does not support / allow creation of new nodes because new nodes should be created through
  * the createNode() method of an existing reference node.
  *
  * Also note that the context's "current node" is not affected by this object converter, you will need to set it to
  * whatever node your "current" node is, if any.
  *
  * All elements in the source array which start with two underscores (like __contextNodePath) are specially treated
  * by this converter.
  *
  * All elements in the source array which start with a *single underscore (like _hidden) are *directly* set on the Node
  * object.
  *
  * All other elements, not being prefixed with underscore, are properties of the node.
  *
  * @param string|array $source Either a string or array containing the absolute context node path which identifies the node. For example "/sites/mysitecom/homepage/about@user-admin"
  * @param string $targetType not used
  * @param array $subProperties not used
  * @param PropertyMappingConfigurationInterface $configuration
  * @return mixed An object or \Neos\Error\Messages\Error if the input format is not supported or could not be converted for other reasons
  * @throws NodeException
  */
 public function convertFrom($source, $targetType = null, array $subProperties = array(), PropertyMappingConfigurationInterface $configuration = null)
 {
     if (is_string($source)) {
         $source = array('__contextNodePath' => $source);
     }
     if (!is_array($source) || !isset($source['__contextNodePath'])) {
         return new Error('Could not convert ' . gettype($source) . ' to Node object, a valid absolute context node path as a string or array is expected.', 1302879936);
     }
     try {
         $nodePathAndContext = NodePaths::explodeContextPath($source['__contextNodePath']);
         $nodePath = $nodePathAndContext['nodePath'];
         $workspaceName = $nodePathAndContext['workspaceName'];
         $dimensions = $nodePathAndContext['dimensions'];
     } catch (\InvalidArgumentException $exception) {
         return new Error('Could not convert array to Node object because the node path was invalid.', 1285162903);
     }
     $context = $this->contextFactory->create($this->prepareContextProperties($workspaceName, $configuration, $dimensions));
     $workspace = $context->getWorkspace(false);
     if (!$workspace) {
         return new Error(sprintf('Could not convert the given source to Node object because the workspace "%s" as specified in the context node path does not exist.', $workspaceName), 1383577859);
     }
     $node = $context->getNode($nodePath);
     if (!$node) {
         return new Error(sprintf('Could not convert array to Node object because the node "%s" does not exist.', $nodePath), 1370502328);
     }
     if (isset($source['_nodeType']) && $source['_nodeType'] !== $node->getNodeType()->getName()) {
         if ($context->getWorkspace()->getName() === 'live') {
             throw new NodeException('Could not convert the node type in live workspace', 1429989736);
         }
         $oldNodeType = $node->getNodeType();
         $targetNodeType = $this->nodeTypeManager->getNodeType($source['_nodeType']);
         $node->setNodeType($targetNodeType);
         $this->nodeService->setDefaultValues($node);
         $this->nodeService->cleanUpAutoCreatedChildNodes($node, $oldNodeType);
         $this->nodeService->createChildNodes($node);
     }
     unset($source['_nodeType']);
     $this->setNodeProperties($node, $node->getNodeType(), $source, $context, $configuration);
     return $node;
 }
コード例 #4
0
 /**
  * Creates and persists a node from the given $nodeTemplate as child node
  *
  * @param NodeTemplate $nodeTemplate
  * @param string $nodeName name of the new node. If not specified the name of the nodeTemplate will be used.
  * @param Workspace $workspace
  * @param array $dimensions
  * @return 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;
 }
コード例 #5
0
 /**
  * Move the given node instance to the target workspace
  *
  * If no target node variant (having the same dimension values) exists in the target workspace, the node that
  * is published will be used as a new node variant in the target workspace.
  *
  * @param NodeInterface $node The node to publish
  * @param Workspace $targetWorkspace The workspace to publish to
  * @return void
  */
 protected function moveNodeVariantToTargetWorkspace(NodeInterface $node, Workspace $targetWorkspace)
 {
     $nodeData = $node->getNodeData();
     $this->handleShadowNodeData($nodeData, $targetWorkspace, $nodeData);
     // Technically this shouldn't be needed but due to doctrines behavior we need it.
     if ($nodeData->isRemoved() && $targetWorkspace->getBaseWorkspace() === null) {
         $this->nodeDataRepository->remove($nodeData);
         return;
     }
     $nodeData->setMovedTo(null);
     $nodeData->setWorkspace($targetWorkspace);
     $nodeData->setLastPublicationDateTime($this->now);
     $node->setNodeDataIsMatchingContext(null);
     $this->nodeService->cleanUpProperties($node);
 }