/**
  * @param NodeInterface $contextNode The node for which the preceding node should be found
  * @return NodeInterface The following node of $contextNode or NULL
  */
 protected function getNextForNode($contextNode)
 {
     $nodesInContext = $contextNode->getParent()->getChildNodes();
     for ($i = 1; $i < count($nodesInContext); $i++) {
         if ($nodesInContext[$i - 1] === $contextNode) {
             return $nodesInContext[$i];
         }
     }
     return null;
 }
 /**
  * @param NodeInterface $contextNode The node for which the preceding node should be found
  * @return NodeInterface The preceding node of $contextNode or NULL
  */
 protected function getPrevForNode($contextNode)
 {
     $nodesInContext = $contextNode->getParent()->getChildNodes();
     for ($i = 0; $i < count($nodesInContext) - 1; $i++) {
         if ($nodesInContext[$i + 1] === $contextNode) {
             return $nodesInContext[$i];
         }
     }
     return NULL;
 }
 /**
  * @param NodeInterface $contextNode The node for which the preceding node should be found
  * @return NodeInterface The preceding nodes of $contextNode or NULL
  */
 protected function getPrevForNode(NodeInterface $contextNode)
 {
     $nodesInContext = $contextNode->getParent()->getChildNodes();
     $count = count($nodesInContext) - 1;
     for ($i = $count; $i > 0; $i--) {
         if ($nodesInContext[$i] === $contextNode) {
             unset($nodesInContext[$i]);
             return array_values($nodesInContext);
         } else {
             unset($nodesInContext[$i]);
         }
     }
     return null;
 }
 /**
  * @param NodeInterface $contextNode The node for which the preceding node should be found
  * @return NodeInterface The preceding nodes of $contextNode or NULL
  */
 protected function getNextForNode(NodeInterface $contextNode)
 {
     $nodesInContext = $contextNode->getParent()->getChildNodes();
     $count = count($nodesInContext);
     for ($i = 0; $i < $count; $i++) {
         if ($nodesInContext[$i] === $contextNode) {
             unset($nodesInContext[$i]);
             return array_values($nodesInContext);
         } else {
             unset($nodesInContext[$i]);
         }
     }
     return NULL;
 }
Exemple #5
0
 /**
  * Copies this node after the given node
  *
  * @param \TYPO3\TYPO3CR\Domain\Model\NodeInterface $referenceNode
  * @param string $nodeName
  * @return \TYPO3\TYPO3CR\Domain\Model\NodeInterface
  * @throws NodeExistsException
  * @api
  */
 public function copyAfter(NodeInterface $referenceNode, $nodeName)
 {
     if ($referenceNode->getParent()->getNode($nodeName) !== NULL) {
         throw new NodeExistsException('Node with path "' . $referenceNode->getParent()->getPath() . '/' . $nodeName . '" already exists.', 1292503466);
     }
     if (!$this->isNodeDataMatchingContext()) {
         $this->materializeNodeData();
     }
     $copiedNode = $this->createRecursiveCopy($referenceNode, $nodeName);
     $copiedNode->moveAfter($referenceNode);
     $this->context->getFirstLevelNodeCache()->flush();
     $this->emitNodeAdded($copiedNode);
     return $copiedNode;
 }
 /**
  * @param NodeInterface $targetNode
  * @param string $position
  * @return NodeInterface
  */
 protected function getDesignatedParentNode(NodeInterface $targetNode, $position)
 {
     $referenceNode = $targetNode;
     if (in_array($position, array('before', 'after'))) {
         $referenceNode = $targetNode->getParent();
     }
     return $referenceNode;
 }
 /**
  * Copies this node after the given node
  *
  * @param NodeInterface $referenceNode
  * @param string $nodeName
  * @return NodeInterface
  * @throws NodeExistsException
  * @throws NodeConstraintException
  * @api
  */
 public function copyAfter(NodeInterface $referenceNode, $nodeName)
 {
     if ($referenceNode->getParent()->getNode($nodeName) !== null) {
         throw new NodeExistsException('Node with path "' . $referenceNode->getParent()->getPath() . '/' . $nodeName . '" already exists.', 1292503466);
     }
     if (!$referenceNode->getParent()->isNodeTypeAllowedAsChildNode($this->getNodeType())) {
         throw new NodeConstraintException('Cannot copy ' . $this->__toString() . ' after ' . $referenceNode->__toString(), 1404648170);
     }
     $this->emitBeforeNodeCopy($this, $referenceNode->getParent());
     $copiedNode = $this->createRecursiveCopy($referenceNode->getParent(), $nodeName, $this->getNodeType()->isAggregate());
     $copiedNode->moveAfter($referenceNode);
     $this->context->getFirstLevelNodeCache()->flush();
     $this->emitNodeAdded($copiedNode);
     $this->emitAfterNodeCopy($copiedNode, $referenceNode->getParent());
     return $copiedNode;
 }
 protected function getParents(NodeInterface $contextNode, NodeInterface $siteNode)
 {
     $parents = array();
     while ($contextNode !== $siteNode && $contextNode->getParent() !== null) {
         $contextNode = $contextNode->getParent();
         $parents[] = $contextNode;
     }
     return $parents;
 }
 /**
  * Collects metadata attributes used to allow editing of the node in the Neos backend.
  *
  * @param array $attributes
  * @param NodeInterface $node
  * @return array
  */
 protected function addGenericEditingMetadata(array $attributes, NodeInterface $node)
 {
     $attributes['typeof'] = 'typo3:' . $node->getNodeType()->getName();
     $attributes['about'] = $node->getContextPath();
     $attributes['data-node-_identifier'] = $node->getIdentifier();
     $attributes['data-node-__workspace-name'] = $node->getWorkspace()->getName();
     $attributes['data-node-__label'] = $node->getLabel();
     if ($node->getNodeType()->isOfType('TYPO3.Neos:ContentCollection')) {
         $attributes['rel'] = 'typo3:content-collection';
     }
     // these properties are needed together with the current NodeType to evaluate Node Type Constraints
     // TODO: this can probably be greatly cleaned up once we do not use CreateJS or VIE anymore.
     if ($node->getParent()) {
         $attributes['data-node-__parent-node-type'] = $node->getParent()->getNodeType()->getName();
     }
     if ($node->isAutoCreated()) {
         $attributes['data-node-_name'] = $node->getName();
         $attributes['data-node-_is-autocreated'] = 'true';
     }
     if ($node->getParent() && $node->getParent()->isAutoCreated()) {
         $attributes['data-node-_parent-is-autocreated'] = 'true';
         // we shall only add these properties if the parent is actually auto-created; as the Node-Type-Switcher in the UI relies on that.
         $attributes['data-node-__parent-node-name'] = $node->getParent()->getName();
         $attributes['data-node-__grandparent-node-type'] = $node->getParent()->getParent()->getNodeType()->getName();
     }
     return $attributes;
 }
 /**
  * Deletes the specified node and all of its sub nodes
  *
  * @param \TYPO3\TYPO3CR\Domain\Model\NodeInterface $node
  * @return void
  * @ExtDirect
  */
 public function deleteAction(\TYPO3\TYPO3CR\Domain\Model\NodeInterface $node)
 {
     //		$node->remove();
     $nextUri = $this->uriBuilder->reset()->setFormat('html')->setCreateAbsoluteUri(TRUE)->uriFor('show', array('node' => $node->getParent()), 'Frontend\\Node', 'TYPO3.TYPO3', '');
     $this->view->assign('value', array('data' => array('nextUri' => $nextUri), 'success' => TRUE));
 }
 /**
  * Create nodes. If any node has defined any sub-nodes again,
  * it calls configureCreateAssistanceChildNodes() recursively.
  *
  * @param NodeInterface $node
  * @param NodeType $nodeType
  * @param array $nodesToCreate
  * @param string $position : before, after, inside
  * @param array $args : arguments to be replaced in in property values (via vsprintf())
  * @return NodeInterface[]
  * @throws NodeConfigurationException
  * @throws \TYPO3\TYPO3CR\Exception\NodeConstraintException
  * @throws \TYPO3\TYPO3CR\Exception\NodeException
  * @throws \TYPO3\TYPO3CR\Exception\NodeExistsException
  * @throws \TYPO3\TYPO3CR\Exception\NodeTypeNotFoundException
  */
 protected function createNodes(NodeInterface $node, NodeType $nodeType, array $nodesToCreate, $position, array $args = [])
 {
     $createdNodes = [];
     foreach ($nodesToCreate as $config) {
         if (false === isset($config['nodeType'])) {
             throw new NodeConfigurationException("Missing `nodeType` to create for node `{$nodeType->getName()}`.", 1432821591);
         }
         // New node is just about to be created. Do we need to switch off auto-childNodes creation
         if (isset($config['enableAutoCreateNodes']) && false === $config['enableAutoCreateNodes']) {
             $this->enableAutoCreateNodes = false;
         }
         $newNodeType = $this->nodeTypeManager->getNodeType($config['nodeType']);
         if ('before' === $position) {
             $newNode = $node->getParent()->createNode(uniqid('node-'), $newNodeType);
             $newNode->moveBefore($node);
         } elseif ('after' === $position) {
             $newNode = $node->getParent()->createNode(uniqid('node-'), $newNodeType);
             $newNode->moveAfter($node);
         } else {
             $newNode = $node->createNode(uniqid('node-'), $newNodeType);
         }
         // Restore $enableAutoCreateNodes after node has been created
         $this->enableAutoCreateNodes = true;
         $createdNodes[$newNode->getIdentifier()] = $newNode;
         if (isset($config['properties'])) {
             $this->setNodeProperties($newNode, $config['properties'], $args);
         }
         // do we have another [beforeNodes, childNodes, afterNodes] to create? Go on...
         $this->configureCreateAssistanceChildNodes($newNode, $newNodeType, $config, $args);
     }
     return $createdNodes;
 }
 /**
  * @param NodeInterface $node
  * @return NodeInterface
  */
 protected function findFulltextRoot(NodeInterface $node)
 {
     if (in_array($node->getNodeType()->getName(), $this->fulltextRootNodeTypes)) {
         return NULL;
     }
     $currentNode = $node->getParent();
     while ($currentNode !== NULL) {
         if (in_array($currentNode->getNodeType()->getName(), $this->fulltextRootNodeTypes)) {
             return $currentNode;
         }
         $currentNode = $currentNode->getParent();
     }
     return NULL;
 }