/** * @test */ public function inheritanceBasedConstraintsWork() { $testingNodeTypeWithSubnodes = $this->nodeTypeManager->getNodeType('TYPO3.TYPO3CR.Testing:NodeTypeWithSubnodes'); $testingNodeTypeThatInheritsFromDocumentType = $this->nodeTypeManager->getNodeType('TYPO3.TYPO3CR.Testing:Page'); $nodeWithChildNode = $this->rootNode->createNode('node-with-child-node', $testingNodeTypeWithSubnodes); $nodeWithChildNode->createNode('page', $testingNodeTypeThatInheritsFromDocumentType); $this->assertCount(2, $nodeWithChildNode->getChildNodes()); }
/** * @param NodeInterface $parentNode * @param NodeType $nodeType * @return NodeInterface|void */ public function create(NodeInterface $parentNode, NodeType $nodeType) { $title = Company::name(); $name = Utility::renderValidNodeName($title); $childrenNode = $parentNode->createNode($name, $nodeType); $childrenNode->setProperty('title', $title); return $childrenNode; }
/** * Set up the following node structure: * * /headline (TYPO3.TYPO3CR.Testing:Headline) * - live workspace * - title: Hello World * - personal workspace * - title: Hello World * - subtitle: Brave new world * /headline with language=de_DE * - personal workspace * - title: Hallo Welt * @return void */ protected function setupNodeWithShadowNodeInPersonalWorkspace() { $nodeTypeManager = $this->objectManager->get(NodeTypeManager::class); $headlineNode = $this->rootNodeInLiveWorkspace->createNode('headline', $nodeTypeManager->getNodeType('TYPO3.TYPO3CR.Testing:Headline')); $headlineNode->setProperty('title', 'Hello World'); $headlineNodeInPersonalWorkspace = $this->rootNodeInPersonalWorkspace->getNode('headline'); $headlineNodeInPersonalWorkspace->setProperty('subtitle', 'Brave new world'); $germanContext = $this->contextFactory->create(array('workspaceName' => $this->currentTestWorkspaceName, 'dimensions' => array('language' => array('de_DE', 'mul_ZZ')))); $headlineInGerman = $germanContext->getNode('/headline'); $headlineInGerman->setProperty('title', 'Hallo Welt'); $this->flushNodeChanges(); }
/** * Creates some sample nodes to run tests against */ protected function createNodesForNodeSearchTest() { $newNode1 = $this->siteNode->createNode('test-node-1', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page')); $newNode1->setProperty('title', 'chicken'); $newNode2 = $this->siteNode->createNode('test-node-2', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page')); $newNode2->setProperty('title', 'chicken'); $newNode3 = $this->siteNode->createNode('test-node-3', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page')); $newNode3->setProperty('title', 'egg'); $dimensionContext = $this->contextFactory->create(['workspaceName' => 'live', 'dimensions' => ['language' => ['de']]]); $translatedNode3 = $dimensionContext->adoptNode($newNode3, true); $translatedNode3->setProperty('title', 'De'); $this->persistenceManager->persistAll(); sleep(2); if (self::$indexInitialized === true) { return; } $this->nodeIndexCommandController->buildCommand(null, false, null, 'functionaltest'); self::$indexInitialized = true; }
/** * Creates missing child nodes for the given node. * * @param NodeInterface $node * @return void */ public function createChildNodes(NodeInterface $node) { $nodeType = $node->getNodeType(); foreach ($nodeType->getAutoCreatedChildNodes() as $childNodeName => $childNodeType) { try { $node->createNode($childNodeName, $childNodeType); } catch (NodeExistsException $exception) { // If you have a node that has been marked as removed, but is needed again // the old node is recovered $childNodePath = NodePaths::addNodePathSegment($node->getPath(), $childNodeName); $contextProperties = $node->getContext()->getProperties(); $contextProperties['removedContentShown'] = true; $context = $this->contextFactory->create($contextProperties); $childNode = $context->getNode($childNodePath); if ($childNode->isRemoved()) { $childNode->setRemoved(false); } } } }
/** * @param NodeInterface $parentNode * @param NodeType $nodeType * @return NodeInterface */ public function create(NodeInterface $parentNode, NodeType $nodeType) { $contentNode = $parentNode->createNode(uniqid('node'), $nodeType); $contentNode->setProperty('text', sprintf('<p>%s</p>', Lorem::paragraph(rand(1, 10)))); return $contentNode; }
/** * 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; }
/** * 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; }
/** * @param \TYPO3\TYPO3CR\Domain\Model\NodeInterface $referenceNode * @param array $nodeData * @param string $position * @return \TYPO3\TYPO3CR\Domain\Model\Node * @throws \InvalidArgumentException */ protected function createNewNode(\TYPO3\TYPO3CR\Domain\Model\NodeInterface $referenceNode, array $nodeData, $position) { if (!in_array($position, array('before', 'into', 'after'), TRUE)) { throw new \InvalidArgumentException('The position should be one of the following: "before", "into", "after".', 1347133640); } if (empty($nodeData['nodeName'])) { $nodeData['nodeName'] = uniqid('node'); } $contentType = $this->contentTypeManager->getContentType($nodeData['contentType']); if ($position === 'into') { $newNode = $referenceNode->createNode($nodeData['nodeName'], $contentType); } else { $parentNode = $referenceNode->getParent(); $newNode = $parentNode->createNode($nodeData['nodeName'], $contentType); if ($position === 'before') { $newNode->moveBefore($referenceNode); } else { $newNode->moveAfter($referenceNode); } } if (isset($nodeData['properties']) && is_array($nodeData['properties'])) { foreach ($nodeData['properties'] as $propertyName => $propertyValue) { $newNode->setProperty($propertyName, $propertyValue); } } return $newNode; }
/** * Configure grid row element (M12.Foundation:GridRowXCol): * - add child columns * - set default column width (based on num of columns and grid size) * - create text node with sample content in each column * * @param NodeInterface $node * @param NodeType $nodeType : one of M12.Foundation:GridRowXCol * @throws \TYPO3\TYPO3CR\Exception\NodeTypeNotFoundException */ protected function configureGridRow(NodeInterface $node, NodeType $nodeType) { if (false === $this->enableAutoCreateNodes) { return; } $gs = $this->gridSize; // Get number of columns to create from M12.Foundation:GridRowXCol node type name $cols = (int) substr($nodeType->getName(), -4, 1); for ($k = 1; $k <= $cols; $k++) { $newNodeType = $this->nodeTypeManager->getNodeType('M12.Foundation:GridColumn'); $newNode = $node->createNode(uniqid('node-'), $newNodeType); // configure sensible default columns width if (1 === $cols) { $newNode->setProperty('classGridSize', ['small-' . $gs]); } elseif (4 === $cols) { $newNode->setProperty('classGridSize', ['small-' . $gs, 'medium-' . $gs / 2, 'large-' . $gs / 4]); } else { $newNode->setProperty('classGridSize', ['small-' . $gs, 'medium-' . (int) $gs / $cols]); } // Create sample content in each column $config = $this->getAssistanceConfigForNodeType($newNodeType->getName()); $this->configureCreateAssistanceChildNodes($newNode, $newNodeType, $config, [$k]); } }
/** * Gets a storage folder by type, and creates it if needed * * @param string $nodeTypeName * @param NodeInterface $rootNode * @return NodeInterface */ protected function getStorageFolder($nodeTypeName, NodeInterface $rootNode) { $query = new FlowQuery([$rootNode]); $storageFolder = $query->find('[instanceof ' . $nodeTypeName . ']')->get(0); if (!$storageFolder instanceof NodeInterface) { $storageFolder = $rootNode->createNode(uniqid('node-'), $this->nodeTypeManager->getNodeType($nodeTypeName)); } return $storageFolder; }
public function testNodeConfigurator_Form() { $newNode = $this->rootCC->createNode(uniqid('node-'), $this->nodeTypeManager->getNodeType('M12.Foundation:Form')); $this->assertEquals(1, $newNode->getNumberOfChildNodes()); }