/**
  * Creates a new comment
  *
  * @param \TYPO3\TYPO3CR\Domain\Model\NodeInterface $postNode The post node which will contain the new comment
  * @param \TYPO3\TYPO3CR\Domain\Model\NodeTemplate<RobertLemke.Plugin.Blog:Comment> $nodeTemplate
  * @return void
  */
 public function createAction(NodeInterface $postNode, NodeTemplate $newComment)
 {
     # Workaround until we can validate node templates properly:
     if (strlen($newComment->getProperty('author')) < 2) {
         $this->addFlashMessage('Your comment was NOT created - please specify your name.');
         $this->redirect('show', 'Frontend\\Node', 'TYPO3.Neos', array('node' => $postNode));
     }
     if (strlen($newComment->getProperty('text')) < 5) {
         $this->addFlashMessage('Your comment was NOT created - it was too short.');
         $this->redirect('show', 'Frontend\\Node', 'TYPO3.Neos', array('node' => $postNode));
     }
     if (filter_var($newComment->getProperty('emailAddress'), FILTER_VALIDATE_EMAIL) === FALSE) {
         $this->addFlashMessage('Your comment was NOT created - you must specify a valid email address.');
         $this->redirect('show', 'Frontend\\Node', 'TYPO3.Neos', array('node' => $postNode));
     }
     $commentNode = $postNode->getNode('comments')->createNodeFromTemplate($newComment, uniqid('comment-'));
     $commentNode->setProperty('spam', FALSE);
     $commentNode->setProperty('datePublished', new \DateTime());
     if ($this->akismetService->isCommentSpam('', $commentNode->getProperty('text'), 'comment', $commentNode->getProperty('author'), $commentNode->getProperty('emailAddress'))) {
         $commentNode->setProperty('spam', TRUE);
     }
     $this->addFlashMessage('Your new comment was created.');
     $this->emitCommentCreated($commentNode, $postNode);
     $this->redirect('show', 'Frontend\\Node', 'TYPO3.Neos', array('node' => $postNode));
 }
 /**
  * Converts the specified node path into a Node.
  *
  * The node path must be an absolute context node path and can be specified as a string or as an array item with the
  * key "__contextNodePath". The latter case is for updating existing nodes.
  *
  * This conversion method supports creation of new nodes because new nodes
  *
  * Also note that the context's "current node" is not affected by this object converter, you will need to set it to
  * whatever node your "current" node is, if any.
  *
  * All elements in the source array which start with two underscores (like __contextNodePath) are specially treated
  * by this converter.
  *
  * All elements in the source array which start with a *single underscore (like _hidden) are *directly* set on the Node
  * object.
  *
  * All other elements, not being prefixed with underscore, are properties of the node.
  *
  *
  * @param string|array $source Either a string or array containing the absolute context node path which identifies the node. For example "/sites/mysitecom/homepage/about@user-admin"
  * @param string $targetType not used
  * @param array $subProperties not used
  * @param PropertyMappingConfigurationInterface $configuration not used
  * @return mixed An object or \TYPO3\Flow\Error\Error if the input format is not supported or could not be converted for other reasons
  * @throws \Exception
  */
 public function convertFrom($source, $targetType, array $subProperties = array(), PropertyMappingConfigurationInterface $configuration = null)
 {
     $nodeTemplate = new NodeTemplate();
     $nodeType = $this->extractNodeType($targetType, $source);
     $nodeTemplate->setNodeType($nodeType);
     // we don't need a context or workspace for creating NodeTemplate objects, but in order to satisfy the method
     // signature of setNodeProperties(), we do need one:
     $context = $this->contextFactory->create($this->prepareContextProperties('live'));
     $this->setNodeProperties($nodeTemplate, $nodeTemplate->getNodeType(), $source, $context);
     return $nodeTemplate;
 }
 /**
  * @param Context $context
  * @return NodeInterface
  * @throws NodeTypeNotFoundException
  * @throws NodeConfigurationException
  */
 public function findOrCreateMetaDataRootNode(Context $context)
 {
     if ($this->metaDataRootNode instanceof NodeInterface) {
         return $this->metaDataRootNode;
     }
     $metaDataRootNodeData = $this->metaDataRepository->findOneByPath('/' . MetaDataRepository::METADATA_ROOT_NODE_NAME, $context->getWorkspace());
     if ($metaDataRootNodeData !== null) {
         $metaDataRootNode = $this->nodeFactory->createFromNodeData($metaDataRootNodeData, $context);
         return $metaDataRootNode;
     }
     $nodeTemplate = new NodeTemplate();
     $nodeTemplate->setNodeType($this->nodeTypeManager->getNodeType('unstructured'));
     $nodeTemplate->setName(MetaDataRepository::METADATA_ROOT_NODE_NAME);
     $context = $this->contextFactory->create(['workspaceName' => 'live']);
     $rootNode = $context->getRootNode();
     $this->metaDataRootNode = $rootNode->createNodeFromTemplate($nodeTemplate);
     $this->persistenceManager->persistAll();
     return $this->metaDataRootNode;
 }
 /**
  * Creates and persists a node from the given $nodeTemplate as child node
  *
  * @param \TYPO3\TYPO3CR\Domain\Model\NodeTemplate $nodeTemplate
  * @param string $nodeName name of the new node. If not specified the name of the nodeTemplate will be used.
  * @param \TYPO3\TYPO3CR\Domain\Model\Workspace $workspace
  * @param array $dimensions
  * @return \TYPO3\TYPO3CR\Domain\Model\NodeData the freshly generated node
  */
 public function createNodeDataFromTemplate(NodeTemplate $nodeTemplate, $nodeName = null, Workspace $workspace = null, array $dimensions = null)
 {
     $newNodeName = $nodeName !== null ? $nodeName : $nodeTemplate->getName();
     $possibleNodeName = $this->nodeService->generateUniqueNodeName($this->getPath(), $newNodeName);
     $newNodeData = $this->createNodeData($possibleNodeName, $nodeTemplate->getNodeType(), $nodeTemplate->getIdentifier(), $workspace, $dimensions);
     $newNodeData->similarize($nodeTemplate);
     return $newNodeData;
 }
 /**
  * @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());
 }
 /**
  * @param Dto\Asset $asset
  * @param NodeType $nodeType
  * @return NodeTemplate
  */
 protected function createAssetNodeTemplate(Dto\Asset $asset, NodeType $nodeType)
 {
     $assetNodeTemplate = new NodeTemplate();
     $assetNodeTemplate->setNodeType($nodeType);
     $assetNodeTemplate->setName($asset->getIdentifier());
     return $assetNodeTemplate;
 }
Пример #7
0
 /**
  * Creates and persists a node from the given $nodeTemplate as child node
  *
  * @param \TYPO3\TYPO3CR\Domain\Model\NodeTemplate $nodeTemplate
  * @param string $nodeName name of the new node. If not specified the name of the nodeTemplate will be used.
  * @param \TYPO3\TYPO3CR\Domain\Model\Workspace $workspace
  * @param array $dimensions
  * @return \TYPO3\TYPO3CR\Domain\Model\NodeData the freshly generated node
  */
 public function createNodeDataFromTemplate(NodeTemplate $nodeTemplate, $nodeName = NULL, Workspace $workspace = NULL, array $dimensions = NULL)
 {
     $newNodeName = $nodeName !== NULL ? $nodeName : $nodeTemplate->getName();
     $possibleNodeName = $newNodeName;
     $counter = 1;
     while ($this->getNode($possibleNodeName) !== NULL) {
         $possibleNodeName = $newNodeName . '-' . $counter++;
     }
     $newNodeData = $this->createNodeData($possibleNodeName, $nodeTemplate->getNodeType(), $nodeTemplate->getIdentifier(), $workspace, $dimensions);
     $newNodeData->similarize($nodeTemplate);
     return $newNodeData;
 }
 /**
  * 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);
 }
 /**
  * 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);
     }
 }
 /**
  * @test
  * @expectedException \InvalidArgumentException
  */
 public function setNameWithInvalidNameThrowsException()
 {
     $nodeTemplate = new NodeTemplate();
     $nodeTemplate->setName(',?/invalid-node-name');
 }