getChildNodes() public method

If a node type is specified, only nodes of that type are returned.
public getChildNodes ( string $nodeTypeFilter = null, integer $limit = null, integer $offset = null ) : array<\Neos\ContentRepository\Domain\Model\NodeInterface>
$nodeTypeFilter string If specified, only nodes with that node type are considered
$limit integer An optional limit for the number of nodes to find. Added or removed nodes can still change the number nodes!
$offset integer An optional offset for the query
return array<\Neos\ContentRepository\Domain\Model\NodeInterface>
 /**
  * Publishes the given node to the specified target workspace. If no workspace is specified, the base workspace
  * is assumed.
  *
  * If the given node is a Document or has ContentCollection child nodes, these nodes are published as well.
  *
  * @param NodeInterface $node
  * @param Workspace $targetWorkspace If not set the base workspace is assumed to be the publishing target
  * @return void
  * @api
  */
 public function publishNode(NodeInterface $node, Workspace $targetWorkspace = null)
 {
     if ($targetWorkspace === null) {
         $targetWorkspace = $node->getWorkspace()->getBaseWorkspace();
     }
     if (!$targetWorkspace instanceof Workspace) {
         return;
     }
     $nodes = array($node);
     $nodeType = $node->getNodeType();
     if ($nodeType->isOfType('Neos.Neos:Document') || $nodeType->hasConfiguration('childNodes')) {
         foreach ($node->getChildNodes('Neos.Neos:ContentCollection') as $contentCollectionNode) {
             array_push($nodes, $contentCollectionNode);
         }
     }
     $sourceWorkspace = $node->getWorkspace();
     $sourceWorkspace->publishNodes($nodes, $targetWorkspace);
     $this->emitNodePublished($node, $targetWorkspace);
 }
 /**
  * @param integer $currentPage
  * @return void
  * @throws PageNotFoundException
  */
 public function indexAction($currentPage = 1)
 {
     $this->currentPage = (int) $currentPage;
     if ($this->currentPage < 1) {
         $this->currentPage = 1;
     } elseif ($this->currentPage > $this->numberOfPages) {
         throw new PageNotFoundException();
     }
     $itemsPerPage = (int) $this->configuration['itemsPerPage'];
     if ($this->maximumNumberOfNodes > 0 && $this->maximumNumberOfNodes < $itemsPerPage) {
         $itemsPerPage = $this->maximumNumberOfNodes;
     }
     $offset = $this->currentPage > 1 ? (int) ($itemsPerPage * ($this->currentPage - 1)) : null;
     if ($this->parentNode === null) {
         $nodes = array_slice($this->nodes, $offset, $itemsPerPage);
     } else {
         $nodes = $this->parentNode->getChildNodes($this->nodeTypeFilter, $itemsPerPage, $offset);
     }
     $this->view->assign('contentArguments', array($this->widgetConfiguration['as'] => $nodes));
     $this->view->assign('configuration', $this->configuration);
     $this->view->assign('pagination', $this->buildPagination());
 }
Ejemplo n.º 3
0
 /**
  * Collect node data and traverse child nodes
  *
  * @param array &$nodes
  * @param NodeInterface $node
  * @param string $nodeTypeFilter
  * @param integer $depth levels of child nodes to fetch. 0 = unlimited
  * @param \Neos\ContentRepository\Domain\Model\NodeInterface $untilNode if given, expand all nodes on the rootline towards $untilNode, no matter what is defined with $depth.
  * @param integer $recursionPointer current recursion level
  * @return void
  */
 protected function collectChildNodeData(array &$nodes, NodeInterface $node, $nodeTypeFilter, $depth = 0, NodeInterface $untilNode = null, $recursionPointer = 1)
 {
     foreach ($node->getChildNodes($nodeTypeFilter) as $childNode) {
         if (!$this->privilegeManager->isGranted(NodeTreePrivilege::class, new NodePrivilegeSubject($childNode))) {
             continue;
         }
         /** @var NodeInterface $childNode */
         $expand = $depth === 0 || $recursionPointer < $depth;
         if ($expand === false && $untilNode !== null && strpos($untilNode->getPath(), $childNode->getPath()) === 0 && $childNode !== $untilNode) {
             // in case $untilNode is set, and the current childNode is on the rootline of $untilNode (and not the node itself), expand the node.
             $expand = true;
         }
         switch ($this->outputStyle) {
             case self::STYLE_LIST:
                 $nodeType = $childNode->getNodeType()->getName();
                 $properties = $childNode->getProperties();
                 $properties['__contextNodePath'] = $childNode->getContextPath();
                 $properties['__workspaceName'] = $childNode->getWorkspace()->getName();
                 $properties['__nodeName'] = $childNode->getName();
                 $properties['__nodeType'] = $nodeType;
                 $properties['__title'] = $nodeType === 'Neos.Neos:Document' ? $childNode->getProperty('title') : $childNode->getLabel();
                 array_push($nodes, $properties);
                 if ($expand) {
                     $this->collectChildNodeData($nodes, $childNode, $nodeTypeFilter, $depth, $untilNode, $recursionPointer + 1);
                 }
                 break;
             case self::STYLE_TREE:
                 $children = array();
                 $hasChildNodes = $childNode->hasChildNodes($nodeTypeFilter) === true;
                 if ($expand && $hasChildNodes) {
                     $this->collectChildNodeData($children, $childNode, $nodeTypeFilter, $depth, $untilNode, $recursionPointer + 1);
                 }
                 array_push($nodes, $this->collectTreeNodeData($childNode, $expand, $children, $hasChildNodes));
         }
     }
 }