Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Add ContentSubgraphInterface::findClosestNode() #4519

Merged
merged 3 commits into from
Sep 21, 2023

Conversation

bwaidelich
Copy link
Member

Resolves: #4517

@mhsdesign
Copy link
Member

Hi, just a though, what about naming it findClosest instead and possibly include the current node in the result set if it matches already?

Then this would be an actual 1 to 1 drop in for findClosestDocumentNode as we want return the current node if its an document already.

$documentNode = $subgraph->findClosestNode($node->nodeAggregateId, FindClosestNodeFilter::create(nodeTypeConstraints: 'Neos.Neos:Document');

..that returns the entry node itself, if it matches the filter
@bwaidelich
Copy link
Member Author

@mhsdesign that's a very good point, that makes the query much more useful. Adjusted with cddc41d

…ntentSubgraphInterface.php

Co-authored-by: Marc Henry Schultz <85400359+mhsdesign@users.noreply.github.com>
@mhsdesign
Copy link
Member

mhsdesign commented Sep 19, 2023

before merging this i would like to discuss how we want to ideally fetch all the necessary nodes for the fusion view.

Based on an entryNode, we need documentNode and siteNode.

So the document node can be found via this PR findClosestNode - but what about the site?

I had the idea to combine both lookups into one query:

$ancestors = $subgraph->findAncestorNodes($node->nodeAggregateId, FindAncestorNodesFilter::create(nodeTypeConstraints: 'Neos.Neos:Document');

$documentNode = $node->nodeType->isOfType('Neos.Neos:Document') ? $node : $ancestors->first();

$siteNode = $ancestors->last();

but i dont know if its a criteria for the homepage node to be of type Neos.Neos:Document? see https://neos-project.slack.com/archives/C3MCBK6S2/p1694339628529459?thread_ts=1694269188.257739&channel=C3MCBK6S2&message_ts=1694339628.529459


the other approach using your findClosestNode and this hacky SiteNodeUtility::findSiteNode

public function findSiteNode(Node $node): Node
{
$previousNode = null;
$subgraph = $this->contentRepositoryRegistry->subgraphForNode($node);
do {
if ($node->nodeType->isOfType('Neos.Neos:Sites')) {
// the Site node is the one one level underneath the "Sites" node.
if (is_null($previousNode)) {
break;
}
return $previousNode;
}
$previousNode = $node;
} while ($node = $subgraph->findParentNode($node->nodeAggregateId));
// no Site node found at rootline
throw new \RuntimeException('No site node found!');
}

$documentNode =  $subgraph->findClosestNode($node->nodeAggregateId, FindClosestNodeFilter::create(nodeTypeConstraints: 'Neos.Neos:Document');

$siteNode = $this->siteNodeUtility->findSiteNode($node);

i just remembered that Bernhard hat the plan to introduce a Neos.Neos:Site root site nodeType: #4531

this would allow to write a querys like:

$documentNode =  $subgraph->findClosestNode($node->nodeAggregateId, FindClosestNodeFilter::create(nodeTypeConstraints: 'Neos.Neos:Document');

$siteNode =  $subgraph->findClosestNode($node->nodeAggregateId, FindClosestNodeFilter::create(nodeTypeConstraints: 'Neos.Neos:Site');

which is imo as perfect as it gets?

@bwaidelich bwaidelich changed the title FEATURE: Add ContentSubgraphInterface::findClosestAncestorNode() FEATURE: Add ContentSubgraphInterface::findClosestNode() Sep 19, 2023
@bwaidelich
Copy link
Member Author

before merging this i would like to discuss how we want to ideally fetch all the necessary nodes for the fusion view

is that really related to this very PR?

the other approach using your findClosestNode and this hacky SiteNodeUtility::findSiteNode

Why is that hacky?

@skurfuerst
Copy link
Member

Hey,

looked at the code, looks great to me.

@bwaidelich IMHO this can be merged. Great work :)

@mhsdesign I do not understand why you want to open up the use cases even more; IMHO these are separate topics.

All the best,
Sebastian

@mhsdesign
Copy link
Member

yes no sorry all fine - that was just the thinking progress in my head ^^

i really like this and lets merge it!

@bwaidelich bwaidelich merged commit f82d8e2 into 9.0 Sep 21, 2023
4 checks passed
@bwaidelich bwaidelich deleted the feature/4517-findClosestAncestorNode branch September 21, 2023 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

FEATURE: Add SubgraphInterface::findClosestNode()
3 participants