Neos\ContentRepository\Domain\Repository\NodeDataRepository::findOneByIdentifier PHP Метод

findOneByIdentifier() публичный Метод

If the node does not exist in the specified workspace, this function will try to find one with the given identifier in one of the base workspaces (if any).
public findOneByIdentifier ( string $identifier, Workspace $workspace, array $dimensions = null ) : NodeData
$identifier string Identifier of the node
$workspace Neos\ContentRepository\Domain\Model\Workspace The containing workspace
$dimensions array An array of dimensions with array of ordered values to use for fallback matching
Результат Neos\ContentRepository\Domain\Model\NodeData The matching node if found, otherwise NULL
    public function findOneByIdentifier($identifier, Workspace $workspace, array $dimensions = null)
    {
        $workspaces = [];
        while ($workspace !== null) {
            /** @var $node NodeData */
            foreach ($this->addedNodes as $node) {
                if ($node->getIdentifier() === $identifier && $node->matchesWorkspaceAndDimensions($workspace, $dimensions)) {
                    return $node;
                }
            }
            /** @var $node NodeData */
            foreach ($this->removedNodes as $node) {
                if ($node->getIdentifier() === $identifier && $node->matchesWorkspaceAndDimensions($workspace, $dimensions)) {
                    return null;
                }
            }
            $workspaces[] = $workspace;
            $workspace = $workspace->getBaseWorkspace();
        }
        $queryBuilder = $this->createQueryBuilder($workspaces);
        if ($dimensions !== null) {
            $this->addDimensionJoinConstraintsToQueryBuilder($queryBuilder, $dimensions);
        } else {
            $dimensions = [];
        }
        $this->addIdentifierConstraintToQueryBuilder($queryBuilder, $identifier);
        $query = $queryBuilder->getQuery();
        $nodes = $query->getResult();
        $foundNodes = $this->reduceNodeVariantsByWorkspacesAndDimensions($nodes, $workspaces, $dimensions);
        $foundNodes = $this->filterRemovedNodes($foundNodes, false);
        if ($foundNodes !== []) {
            return reset($foundNodes);
        }
        return null;
    }

Usage Example

 /**
  * @test
  */
 public function sortByDateTimeDescending()
 {
     $nodesToSort = [$this->nodeDataRepository->findOneByIdentifier('c381f64d-4269-429a-9c21-6d846115addd', $this->context->getWorkspace(true), array()), $this->nodeDataRepository->findOneByIdentifier('c381f64d-4269-429a-9c21-6d846115adde', $this->context->getWorkspace(true), array()), $this->nodeDataRepository->findOneByIdentifier('c381f64d-4269-429a-9c21-6d846115addf', $this->context->getWorkspace(true), array())];
     $correctOrder = [$this->nodeDataRepository->findOneByIdentifier('c381f64d-4269-429a-9c21-6d846115addd', $this->context->getWorkspace(true), array()), $this->nodeDataRepository->findOneByIdentifier('c381f64d-4269-429a-9c21-6d846115addf', $this->context->getWorkspace(true), array()), $this->nodeDataRepository->findOneByIdentifier('c381f64d-4269-429a-9c21-6d846115adde', $this->context->getWorkspace(true), array())];
     $flowQuery = new \Neos\Eel\FlowQuery\FlowQuery($nodesToSort);
     $operation = new SortOperation();
     $operation->evaluate($flowQuery, ['_lastPublicationDateTime', 'DESC']);
     $this->assertEquals($correctOrder, $flowQuery->getContext());
 }
All Usage Examples Of Neos\ContentRepository\Domain\Repository\NodeDataRepository::findOneByIdentifier