/** * Initializes this workspace. * * If this workspace is brand new, a root node is created automatically. * * @param integer $initializationCause * @return void */ public function initializeObject($initializationCause) { if ($initializationCause === ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED) { $this->rootNodeData = new NodeData('/', $this); $this->nodeDataRepository->add($this->rootNodeData); } }
/** * Given a context a new node is returned that is like this node, but * lives in the new context. * * @param \TYPO3\TYPO3CR\Domain\Service\Context $context * @return NodeInterface */ public function createVariantForContext($context) { $nodeData = clone $this->nodeData; $nodeData->adjustToContext($context); $this->nodeDataRepository->add($nodeData); $node = $this->nodeFactory->createFromNodeData($nodeData, $context); $this->context->getFirstLevelNodeCache()->flush(); $this->emitNodeAdded($node); return $node; }
/** * @test */ public function findByParentAndNodeTypeIncludesAddedNodeInRepositoryAndRespectsWorkspaceAndDimensions() { $liveWorkspace = new Workspace('live'); $nodeData = $this->getMockBuilder('TYPO3\\TYPO3CR\\Domain\\Model\\NodeData')->disableOriginalConstructor()->getMock(); $nodeData->expects($this->any())->method('getIdentifier')->will($this->returnValue('abcd-efgh-ijkl-mnop')); $nodeData->expects($this->any())->method('getPath')->will($this->returnValue('/foo/bar')); $nodeData->expects($this->any())->method('getDepth')->will($this->returnValue(2)); $this->nodeDataRepository->add($nodeData); $dimensions = array('persona' => array('everybody'), 'language' => array('de_DE', 'mul_ZZ')); $nodeData->expects($this->atLeastOnce())->method('matchesWorkspaceAndDimensions')->with($liveWorkspace, $dimensions)->will($this->returnValue(TRUE)); $this->nodeDataRepository->expects($this->any())->method('getNodeDataForParentAndNodeType')->will($this->returnValue(array())); $result = $this->nodeDataRepository->findByParentAndNodeType('/foo', NULL, $liveWorkspace, $dimensions); $this->assertCount(1, $result); $fetchedNodeData = reset($result); $this->assertSame($nodeData, $fetchedNodeData); }
/** * Materializes the original node data (of a different workspace) into the current * workspace. * * @return void */ protected function materializeNodeData() { $dimensions = $this->context->getTargetDimensionValues(); $newNodeData = new NodeData($this->nodeData->getPath(), $this->context->getWorkspace(), $this->nodeData->getIdentifier(), $dimensions); $this->nodeDataRepository->add($newNodeData); $newNodeData->similarize($this->nodeData); $this->nodeData = $newNodeData; $this->nodeDataIsMatchingContext = true; $nodeType = $this->getNodeType(); foreach ($nodeType->getAutoCreatedChildNodes() as $childNodeName => $childNodeConfiguration) { $childNode = $this->getNode($childNodeName); if ($childNode instanceof Node && !$childNode->isNodeDataMatchingContext()) { $childNode->materializeNodeData(); } } }
/** * Creates, adds and returns a child node of this node, without setting default * properties or creating subnodes. * * @param string $name Name of the new node * @param \TYPO3\TYPO3CR\Domain\Model\NodeType $nodeType Node type of the new node (optional) * @param string $identifier The identifier of the node, unique within the workspace, optional(!) * @param \TYPO3\TYPO3CR\Domain\Model\Workspace $workspace * @param array $dimensions An array of dimension name to dimension values * @throws NodeExistsException if a node with this path already exists. * @throws \InvalidArgumentException if the node name is not accepted. * @return \TYPO3\TYPO3CR\Domain\Model\NodeData */ public function createSingleNodeData($name, NodeType $nodeType = NULL, $identifier = NULL, Workspace $workspace = NULL, array $dimensions = NULL) { if (!is_string($name) || preg_match(NodeInterface::MATCH_PATTERN_NAME, $name) !== 1) { throw new \InvalidArgumentException('Invalid node name "' . $name . '" (a node name must only contain characters, numbers and the "-" sign).', 1292428697); } $nodeWorkspace = $workspace ?: $this->workspace; $newPath = $this->path . ($this->path === '/' ? '' : '/') . $name; if ($this->nodeDataRepository->findOneByPath($newPath, $nodeWorkspace, $dimensions) !== NULL) { throw new NodeExistsException(sprintf('Node with path "' . $newPath . '" already exists in workspace %s and given dimensions %s.', $nodeWorkspace->getName(), var_export($dimensions, TRUE)), 1292503471); } $newNodeData = new NodeData($newPath, $nodeWorkspace, $identifier, $dimensions); $this->nodeDataRepository->add($newNodeData); $this->nodeDataRepository->setNewIndex($newNodeData, NodeDataRepository::POSITION_LAST); if ($nodeType !== NULL) { $newNodeData->setNodeType($nodeType); } return $newNodeData; }