/** * Creates a new blog post node * * @return void */ public function createAction() { /** @var NodeInterface $blogDocumentNode */ $blogDocumentNode = $this->request->getInternalArgument('__documentNode'); if ($blogDocumentNode === NULL) { return 'Error: The Blog Post Plugin cannot determine the current document node. Please make sure to include this plugin only by inserting it into a page / document.'; } $contentContext = $blogDocumentNode->getContext(); $nodeTemplate = new NodeTemplate(); $nodeTemplate->setNodeType($this->nodeTypeManager->getNodeType('RobertLemke.Plugin.Blog:Post')); $nodeTemplate->setProperty('title', 'A new blog post'); $nodeTemplate->setProperty('datePublished', $contentContext->getCurrentDateTime()); $slug = uniqid('post'); $postNode = $blogDocumentNode->createNodeFromTemplate($nodeTemplate, $slug); $currentlyFirstPostNode = $blogDocumentNode->getPrimaryChildNode(); if ($currentlyFirstPostNode !== NULL) { // FIXME This currently doesn't work, probably due to some TYPO3CR bug / misconception $postNode->moveBefore($currentlyFirstPostNode); } $mainRequest = $this->request->getMainRequest(); $mainUriBuilder = new UriBuilder(); $mainUriBuilder->setRequest($mainRequest); $mainUriBuilder->setFormat('html'); $uri = $mainUriBuilder->reset()->setCreateAbsoluteUri(TRUE)->uriFor('show', array('node' => $postNode)); $this->redirectToUri($uri); }
/** * @test */ public function nodeWithRelatedEntitiesWillTakeCareOfAddingToPersistence() { $identifier = Algorithms::generateUUID(); $template = new NodeTemplate(); $template->setName('new-node'); $template->setIdentifier($identifier); $newEntity = new Fixtures\RelatedEntity(); $newEntity->setFavoritePlace('Reykjavik'); $anotherNewEntity = new Fixtures\RelatedEntity(); $anotherNewEntity->setFavoritePlace('Japan'); $template->setProperty('entity', array($newEntity, $anotherNewEntity)); $rootNode = $this->context->getRootNode(); $newNode = $rootNode->createNodeFromTemplate($template); $this->persistenceManager->persistAll(); $this->persistenceManager->clearState(); $this->inject($this->contextFactory, 'contextInstances', array()); $newLiveContext = $this->contextFactory->create(array('workspaceName' => 'live')); $newNodeAgain = $newLiveContext->getNode('/new-node'); $entityArray = $newNodeAgain->getProperty('entity'); $this->assertCount(2, $entityArray); $this->assertEquals('Japan', $entityArray[1]->getFavoritePlace()); }
/** * importProduct * * @param array $product * @param NodeInterface $startingPointProducts * @param Context $context */ private function importProduct(array $product, NodeInterface $startingPointProducts, Context $context) { $nodeTemplate = new NodeTemplate(); $nodeTemplate->setNodeType($this->nodeTypeManager->getNodeType('Egobude.Products:Product')); $nodeTemplate->setProperty('title', $product['title']); $nodeTemplate->setProperty('sku', $product['sku']); $nodeTemplate->setProperty('price', $product['price']); $similarProducts = $this->getRandomProducts($context, $startingPointProducts); if (!empty($similarProducts)) { $nodeTemplate->setProperty('similarProducts', $similarProducts); } $accessories = $this->getRandomProducts($context, $startingPointProducts); if (!empty($accessories)) { $nodeTemplate->setProperty('accessories', $accessories); } $productNode = $startingPointProducts->createNodeFromTemplate($nodeTemplate); if (!empty($product['description'])) { $description = $product['description']; $mainContentNode = $productNode->getNode('main'); $bodyTemplate = new NodeTemplate(); $bodyTemplate->setNodeType($this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Text')); $bodyTemplate->setProperty('text', $description); $mainContentNode->createNodeFromTemplate($bodyTemplate); } }