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

findOnPath() public method

If some node does not exist in the specified workspace, this function will try to find a corresponding node in one of the base workspaces (if any).
public findOnPath ( string $pathStartingPoint, string $pathEndPoint, Workspace $workspace, array $dimensions = null, boolean $includeRemovedNodes = false, string $nodeTypeFilter = null ) : array<\Neos\ContentRepository\Domain\Model\NodeData>
$pathStartingPoint string Absolute path specifying the starting point
$pathEndPoint string Absolute path specifying the end point
$workspace Neos\ContentRepository\Domain\Model\Workspace The containing workspace
$dimensions array Array of dimensions to array of dimension values
$includeRemovedNodes boolean Should removed nodes be included in the result (defaults to FALSE)
$nodeTypeFilter string Optional filter for the node type of the nodes, supports complex expressions (e.g. "Neos.Neos:Page", "!Neos.Neos:Page,Neos.Neos:Text" or NULL)
return array<\Neos\ContentRepository\Domain\Model\NodeData>
    public function findOnPath($pathStartingPoint, $pathEndPoint, Workspace $workspace, array $dimensions = null, $includeRemovedNodes = false, $nodeTypeFilter = null)
    {
        $pathStartingPoint = strtolower($pathStartingPoint);
        $pathEndPoint = strtolower($pathEndPoint);
        if (NodePaths::isSubPathOf($pathStartingPoint, $pathEndPoint) === false) {
            throw new \InvalidArgumentException('Invalid paths: path of starting point must be first part of end point path.', 1284391181);
        }
        $workspaces = $this->collectWorkspaceAndAllBaseWorkspaces($workspace);
        $queryBuilder = $this->createQueryBuilder($workspaces);
        if ($dimensions !== null) {
            $this->addDimensionJoinConstraintsToQueryBuilder($queryBuilder, $dimensions);
        } else {
            $dimensions = [];
        }
        if ($nodeTypeFilter !== null) {
            $this->addNodeTypeFilterConstraintsToQueryBuilder($queryBuilder, $nodeTypeFilter);
        }
        $pathConstraints = [];
        $constraintPath = $pathStartingPoint;
        $pathConstraints[] = md5($constraintPath);
        $pathSegments = explode('/', NodePaths::getRelativePathBetween($pathStartingPoint, $pathEndPoint));
        foreach ($pathSegments as $pathSegment) {
            $constraintPath = NodePaths::addNodePathSegment($constraintPath, $pathSegment);
            $pathConstraints[] = md5($constraintPath);
        }
        if (count($pathConstraints) > 0) {
            $queryBuilder->andWhere('n.pathHash IN (:paths)')->setParameter('paths', $pathConstraints);
        }
        $query = $queryBuilder->getQuery();
        $foundNodes = $query->getResult();
        $foundNodes = $this->reduceNodeVariantsByWorkspacesAndDimensions($foundNodes, $workspaces, $dimensions);
        $foundNodes = $this->filterNodeDataByBestMatchInContext($foundNodes, $workspaces[0], $dimensions, $includeRemovedNodes);
        if ($includeRemovedNodes === false) {
            $foundNodes = $this->filterRemovedNodes($foundNodes, false);
        }
        $nodesByDepth = [];
        /** @var NodeData $node */
        foreach ($foundNodes as $node) {
            $nodesByDepth[$node->getDepth()] = $node;
        }
        ksort($nodesByDepth);
        return array_values($nodesByDepth);
    }

Usage Example

コード例 #1
0
 /**
  * Finds all nodes lying on the path specified by (and including) the given
  * starting point and end point.
  *
  * @param mixed $startingPoint Either an absolute path or an actual node specifying the starting point, for example /sites/mysitecom
  * @param mixed $endPoint Either an absolute path or an actual node specifying the end point, for example /sites/mysitecom/homepage/subpage
  * @return array<\Neos\ContentRepository\Domain\Model\NodeInterface> The nodes found between and including the given paths or an empty array of none were found
  * @api
  */
 public function getNodesOnPath($startingPoint, $endPoint)
 {
     $startingPointPath = $startingPoint instanceof NodeInterface ? $startingPoint->getPath() : $startingPoint;
     $endPointPath = $endPoint instanceof NodeInterface ? $endPoint->getPath() : $endPoint;
     $nodeDataElements = $this->nodeDataRepository->findOnPath($startingPointPath, $endPointPath, $this->getWorkspace(), $this->getDimensions(), $this->isRemovedContentShown());
     $nodes = array();
     foreach ($nodeDataElements as $nodeData) {
         $node = $this->nodeFactory->createFromNodeData($nodeData, $this);
         if ($node !== null) {
             $nodes[] = $node;
             $this->firstLevelNodeCache->setByPath($node->getPath(), $node);
         }
     }
     return $nodes;
 }