Neos 9: load node via aggregateId only

Hi

Is it possible to load a node within a PHP action controller, if I only have the node’s aggregateId, but no workspace, no content repository and no dimension infos?

My problem is that i wasn’t able to handover the complete node object via GET, so i tried with the aggregateId (which worked), but now I’m unable to load the node via ID.

Best, Jan

Hi there,
for passing nodes via request to a controller, there is the NodeAddress object that can be serialized and deserialized and contains all information that you need - given you have one of the later betas.

1 Like

exactly

$nodeAddressSerialized = NodeAddress::fromNode($node)->toJson();

is your friend.

And for reverse:

$nodeAddress = NodeAddress::fromJsonString($nodeAddressSerialized);
$contentRepository = $this->contentRepositoryRegistry->get($nodeAddress->contentRepositoryId);
$subgraph = $contentRepository->getContentGraph($nodeAddress->workspaceName)
    ->getSubgraph(
        $nodeAddress->dimensionSpacePoint,
        $nodeAddress->workspaceName->isLive()
            ? VisibilityConstraints::frontend()
            : VisibilityConstraints::withoutRestrictions()
    );

$node = $subgraph->findNodeById($nodeAddress->aggregateId);

But you also can just use public myAction(Node $node): void and flow will do the work for you :wink:

1 Like

Thank you so much.

public myAction(Node $node)

did not work for me. But your small script works fine. Fantastic!