Example #1
0
 /**
  * Sets the node type of this node.
  *
  * @param \TYPO3\TYPO3CR\Domain\Model\NodeType $nodeType
  * @return void
  * @api
  */
 public function setNodeType(NodeType $nodeType)
 {
     if (!$this->isNodeDataMatchingContext()) {
         $this->materializeNodeData();
     }
     $this->nodeData->setNodeType($nodeType);
     $this->context->getFirstLevelNodeCache()->flush();
     $this->emitNodeUpdated($this);
 }
Example #2
0
 /**
  * @test
  */
 public function theNodeTypeCanBeSetAndRetrieved()
 {
     $nodeTypeManager = $this->getMock('TYPO3\\TYPO3CR\\Domain\\Service\\NodeTypeManager');
     $nodeTypeManager->expects($this->any())->method('getNodeType')->will($this->returnCallback(function ($name) {
         return new NodeType($name, array(), array());
     }));
     $this->nodeData->_set('nodeTypeManager', $nodeTypeManager);
     $this->assertEquals('unstructured', $this->nodeData->getNodeType()->getName());
     $myNodeType = $nodeTypeManager->getNodeType('typo3:mycontent');
     $this->nodeData->setNodeType($myNodeType);
     $this->assertEquals($myNodeType, $this->nodeData->getNodeType());
 }
 /**
  * @test
  */
 public function theNodeTypeCanBeSetAndRetrieved()
 {
     /** @var NodeTypeManager|\PHPUnit_Framework_MockObject_MockObject $mockNodeTypeManager */
     $mockNodeTypeManager = $this->getMockBuilder('TYPO3\\TYPO3CR\\Domain\\Service\\NodeTypeManager')->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());
 }
 /**
  * If AssetList contains only 1 file, and it's of type Audio, turn it into targetNodeType
  *
  * @param \TYPO3\TYPO3CR\Domain\Model\NodeData $node
  * @return void
  */
 public function execute(\TYPO3\TYPO3CR\Domain\Model\NodeData $node)
 {
     $assets = $node->getProperty($this->sourcePropertyName);
     if (count($assets) === 1) {
         $asset = $assets[0];
         if ($asset instanceof $this->assetType) {
             $nodeType = $this->nodeTypeManager->getNodeType($this->targetNodeType);
             $node->setNodeType($nodeType);
             $node->setProperty($this->targetPropertyName, $asset);
             $node->removeProperty($this->sourcePropertyName);
             echo "Converted AssetList with asset of type" . $this->assetType . " to node of type " . $this->targetNodeType . "\n";
         }
     }
 }
 /**
  * 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 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);
 }
 /**
  * Change the Node Type on the given node.
  *
  * @param \TYPO3\TYPO3CR\Domain\Model\NodeData $node
  * @return void
  */
 public function execute(\TYPO3\TYPO3CR\Domain\Model\NodeData $node)
 {
     $nodeType = $this->nodeTypeManager->getNodeType($this->newType);
     $node->setNodeType($nodeType);
 }