Skip to content

Commit

Permalink
TASK: Introduce Nodes::prepend and cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Aug 15, 2024
1 parent 3bbabb3 commit 5a8ab49
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public function merge(self $other): self
return self::fromArray($nodes);
}

public function prepend(Node $node): self
{
return new self([$node, ...$this->nodes]);
}

public function append(Node $node): self
{
return new self([...$this->nodes, $node]);
Expand Down
30 changes: 16 additions & 14 deletions Neos.Neos/Classes/Controller/Service/NodesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindDescendantNodesFilter;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\ExpandedNodeTypeCriteria;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\NodeTypeCriteria;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\SearchTerm\SearchTerm;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\SearchTerm\SearchTermMatcher;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate;
use Neos\ContentRepository\Core\Projection\ContentGraph\Nodes;
Expand Down Expand Up @@ -113,6 +114,11 @@ public function indexAction(
string $contextNode = null,
array|string $nodeIdentifiers = []
): void {
$searchTerm = $searchTerm === '' ? null : SearchTerm::fulltext($searchTerm);
$nodeTypeCriteria = NodeTypeCriteria::create(
NodeTypeNames::fromStringArray($nodeTypes),
NodeTypeNames::createEmpty()
);
$nodeIds = $nodeIds ?: $nodeIdentifiers;
$nodeIds = is_array($nodeIds) ? $nodeIds : [$nodeIds];
$contentRepositoryId = SiteDetectionResult::fromRequest($this->request->getHttpRequest())
Expand Down Expand Up @@ -143,6 +149,7 @@ public function indexAction(
);
}

$nodes = [];
if ($nodeIds === [] && (!is_null($nodeAddress) || !is_null($nodePath))) {
if (!is_null($nodeAddress)) {
$entryNode = $subgraph->findNodeById($nodeAddress->aggregateId);
Expand All @@ -151,33 +158,28 @@ public function indexAction(
$entryNode = $subgraph->findNodeByAbsolutePath($nodePath);
}

$nodes = Nodes::createEmpty();
if (!is_null($entryNode)) {
$filter = FindDescendantNodesFilter::create(
nodeTypes: NodeTypeCriteria::create(
NodeTypeNames::fromStringArray($nodeTypes),
NodeTypeNames::createEmpty()
),
searchTerm: $searchTerm,
$nodes = $subgraph->findDescendantNodes(
$entryNode->aggregateId,
FindDescendantNodesFilter::create(
nodeTypes: $nodeTypeCriteria,
searchTerm: $searchTerm,
)
);
if (
SearchTermMatcher::matchesNode($entryNode, $filter->searchTerm)
&& ExpandedNodeTypeCriteria::create($filter->nodeTypes, $contentRepository->getNodeTypeManager())
SearchTermMatcher::matchesNode($entryNode, $searchTerm)
&& ExpandedNodeTypeCriteria::create($nodeTypeCriteria, $contentRepository->getNodeTypeManager())
->matches($entryNode->nodeTypeName)
) {
// include the starting node if it matches
$nodes = $nodes->append($entryNode);
$nodes = $nodes->prepend($entryNode);
}
$nodes = $nodes->merge(
$subgraph->findDescendantNodes($entryNode->aggregateId, $filter)
);
}
} else {
if (!empty($searchTerm)) {
throw new \RuntimeException('Combination of $nodeIdentifiers and $searchTerm not supported');
}

$nodes = [];
foreach ($nodeIds as $nodeAggregateId) {
$node = $subgraph->findNodeById(
NodeAggregateId::fromString($nodeAggregateId)
Expand Down
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ parameters:
count: 1
path: Neos.Neos/Classes/Controller/Module/User/UserSettingsController.php

-
message: "#^Parameter \\#2 \\$searchTerm of static method Neos\\\\ContentRepository\\\\Core\\\\Projection\\\\ContentGraph\\\\Filter\\\\SearchTerm\\\\SearchTermMatcher\\:\\:matchesNode\\(\\) expects Neos\\\\ContentRepository\\\\Core\\\\Projection\\\\ContentGraph\\\\Filter\\\\SearchTerm\\\\SearchTerm, Neos\\\\ContentRepository\\\\Core\\\\Projection\\\\ContentGraph\\\\Filter\\\\SearchTerm\\\\SearchTerm\\|null given\\.$#"
count: 1
path: Neos.Neos/Classes/Controller/Service/NodesController.php

-
message: "#^The internal method \"Neos\\\\ContentRepository\\\\Core\\\\Projection\\\\ContentGraph\\\\Filter\\\\NodeType\\\\ExpandedNodeTypeCriteria\\:\\:matches\" is called\\.$#"
count: 1
path: Neos.Neos/Classes/Controller/Service/NodesController.php

-
message: "#^The internal method \"Neos\\\\ContentRepository\\\\Core\\\\DimensionSpace\\\\WeightedDimensionSpacePoint\\:\\:getIdentityHash\" is called\\.$#"
count: 3
Expand Down

0 comments on commit 5a8ab49

Please sign in to comment.