/** * Sets the node type of this node. * * @param NodeType $nodeType * @return void * @api */ public function setNodeType(NodeType $nodeType) { if (!$this->isNodeDataMatchingContext()) { $this->materializeNodeData(); } if ($this->getNodeType() === $nodeType) { return; } $this->nodeData->setNodeType($nodeType); $this->context->getFirstLevelNodeCache()->flush(); $this->emitNodeUpdated($this); }
/** * @test */ public function theNodeTypeCanBeSetAndRetrieved() { /** @var NodeTypeManager|\PHPUnit_Framework_MockObject_MockObject $mockNodeTypeManager */ $mockNodeTypeManager = $this->getMockBuilder(NodeTypeManager::class)->disableOriginalConstructor()->getMock(); $mockNodeTypeManager->expects($this->any())->method('hasNodeType')->will($this->returnValue(true)); $mockNodeTypeManager->expects($this->any())->method('getNodeType')->will($this->returnCallback(function ($name) { return new NodeType($name, array(), array()); })); $this->inject($this->nodeData, 'nodeTypeManager', $mockNodeTypeManager); $this->assertEquals('unstructured', $this->nodeData->getNodeType()->getName()); $myNodeType = $mockNodeTypeManager->getNodeType('typo3:mycontent'); $this->nodeData->setNodeType($myNodeType); $this->assertEquals($myNodeType, $this->nodeData->getNodeType()); }
/** * 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 NodeType $nodeType Node type of the new node (optional) * @param string $identifier The identifier of the node, unique within the workspace, optional(!) * @param 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 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 lowercase characters, numbers and the "-" sign).', 1292428697); } $nodeWorkspace = $workspace ?: $this->workspace; $newPath = NodePaths::addNodePathSegment($this->path, $name); if ($this->nodeDataRepository->findOneByPath($newPath, $nodeWorkspace, $dimensions, null) !== 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); if ($nodeType !== null) { $newNodeData->setNodeType($nodeType); } $this->nodeDataRepository->setNewIndex($newNodeData, NodeDataRepository::POSITION_LAST); return $newNodeData; }
/** * Change the Node Type on the given node. * * @param NodeData $node * @return void */ public function execute(NodeData $node) { $nodeType = $this->nodeTypeManager->getNodeType($this->newType); $node->setNodeType($nodeType); }