Neos\ContentRepository\Domain\Repository\NodeDataRepository::findByParentAndNodeType PHP Method

findByParentAndNodeType() public method

If the $recursive flag is set to TRUE, all matching nodes underneath $parentPath will be returned Note: Filters out removed nodes. The primary sort key is the *index*, the secondary sort key (if indices are equal, which only occurs in very rare cases) is the *identifier*.
public findByParentAndNodeType ( string $parentPath, string $nodeTypeFilter, Workspace $workspace, array $dimensions = null, boolean $removedNodes = false, boolean $recursive = false ) : array<\Neos\ContentRepository\Domain\Model\NodeData>
$parentPath string Absolute path of the parent node
$nodeTypeFilter string Filter the node type of the nodes, allows complex expressions (e.g. "Neos.Neos:Page", "!Neos.Neos:Page,Neos.Neos:Text" or NULL)
$workspace Neos\ContentRepository\Domain\Model\Workspace The containing workspace
$dimensions array An array of dimensions to dimension values
$removedNodes boolean If TRUE the result has ONLY removed nodes. If FALSE removed nodes are NOT inside the result. If NULL the result contains BOTH removed and non-removed nodes. (defaults to FALSE)
$recursive boolean If TRUE *all* matching nodes underneath the specified parent path are returned
return array<\Neos\ContentRepository\Domain\Model\NodeData>
    public function findByParentAndNodeType($parentPath, $nodeTypeFilter, Workspace $workspace, array $dimensions = null, $removedNodes = false, $recursive = false)
    {
        $parentPath = strtolower($parentPath);
        $foundNodes = $this->getNodeDataForParentAndNodeType($parentPath, $nodeTypeFilter, $workspace, $dimensions, $removedNodes, $recursive);
        $childNodeDepth = NodePaths::getPathDepth($parentPath) + 1;
        $constraints = $nodeTypeFilter !== '' ? $this->getNodeTypeFilterConstraintsForDql($nodeTypeFilter) : array();
        /** @var $addedNode NodeData */
        foreach ($this->addedNodes as $addedNode) {
            if (($recursive && $addedNode->getDepth() >= $childNodeDepth || $addedNode->getDepth() === $childNodeDepth) && ($recursive && NodePaths::isSubPathOf($addedNode->getPath(), $parentPath) || NodePaths::getParentPath($addedNode->getPath()) === $parentPath) && $addedNode->matchesWorkspaceAndDimensions($workspace, $dimensions)) {
                $nodeType = $addedNode->getNodeType();
                $disallowed = false;
                foreach ($constraints['includeNodeTypes'] as $includeNodeType) {
                    if (!$nodeType->isOfType($includeNodeType)) {
                        $disallowed = true;
                    }
                }
                foreach ($constraints['excludeNodeTypes'] as $excludeNodeTypes) {
                    if ($nodeType->isOfType($excludeNodeTypes)) {
                        $disallowed = true;
                    }
                }
                if ($disallowed === false) {
                    $foundNodes[$addedNode->getIdentifier()] = $addedNode;
                }
            }
        }
        /** @var $removedNode NodeData */
        foreach ($this->removedNodes as $removedNode) {
            if (($recursive && $removedNode->getDepth() >= $childNodeDepth || $removedNode->getDepth() === $childNodeDepth) && ($recursive && NodePaths::isSubPathOf($removedNode->getPath(), $parentPath) || NodePaths::getParentPath($removedNode->getPath()) === $parentPath) && $removedNode->matchesWorkspaceAndDimensions($workspace, $dimensions)) {
                if (isset($foundNodes[$removedNode->getIdentifier()])) {
                    unset($foundNodes[$removedNode->getIdentifier()]);
                }
            }
        }
        $foundNodes = $this->sortNodesByIndex($foundNodes);
        return $foundNodes;
    }

Usage Example

 /**
  * Method which does the actual work of discarding, includes a protection against endless recursions and
  * multiple discarding of the same node.
  *
  * @param NodeInterface $node The node to discard
  * @param array &$alreadyDiscardedNodeIdentifiers List of node identifiers which already have been discarded during one discardNode() run
  * @return void
  * @throws \Neos\ContentRepository\Exception\WorkspaceException
  */
 protected function doDiscardNode(NodeInterface $node, array &$alreadyDiscardedNodeIdentifiers = [])
 {
     if ($node->getWorkspace()->getBaseWorkspace() === null) {
         throw new WorkspaceException('Nodes in a in a workspace without a base workspace cannot be discarded.', 1395841899);
     }
     if ($node->getPath() === '/') {
         return;
     }
     if (array_search($node->getIdentifier(), $alreadyDiscardedNodeIdentifiers) !== false) {
         return;
     }
     $alreadyDiscardedNodeIdentifiers[] = $node->getIdentifier();
     $possibleShadowNodeData = $this->nodeDataRepository->findOneByMovedTo($node->getNodeData());
     if ($possibleShadowNodeData instanceof NodeData) {
         if ($possibleShadowNodeData->getMovedTo() !== null) {
             $parentBasePath = $node->getPath();
             $affectedChildNodeDataInSameWorkspace = $this->nodeDataRepository->findByParentAndNodeType($parentBasePath, null, $node->getWorkspace(), null, false, true);
             foreach ($affectedChildNodeDataInSameWorkspace as $affectedChildNodeData) {
                 /** @var NodeData $affectedChildNodeData */
                 $affectedChildNode = $this->nodeFactory->createFromNodeData($affectedChildNodeData, $node->getContext());
                 $this->doDiscardNode($affectedChildNode, $alreadyDiscardedNodeIdentifiers);
             }
         }
         $this->nodeDataRepository->remove($possibleShadowNodeData);
     }
     $this->nodeDataRepository->remove($node);
     $this->emitNodeDiscarded($node);
 }
All Usage Examples Of Neos\ContentRepository\Domain\Repository\NodeDataRepository::findByParentAndNodeType