From cd7ad3829d7be00ca512cdecd66c952e5da0e7ae Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:28:55 +0100 Subject: [PATCH] FEATURE: Add `NodeSerializer` --- .../Classes/SharedModel/Node/NodeIdentity.php | 2 +- .../Classes/NodeSerializer.php | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 Neos.ContentRepositoryRegistry/Classes/NodeSerializer.php diff --git a/Neos.ContentRepository.Core/Classes/SharedModel/Node/NodeIdentity.php b/Neos.ContentRepository.Core/Classes/SharedModel/Node/NodeIdentity.php index cc69386ce68..bb4ddfc7f64 100644 --- a/Neos.ContentRepository.Core/Classes/SharedModel/Node/NodeIdentity.php +++ b/Neos.ContentRepository.Core/Classes/SharedModel/Node/NodeIdentity.php @@ -41,7 +41,7 @@ public static function create( WorkspaceName $workspaceName, DimensionSpacePoint $dimensionSpacePoint, NodeAggregateId $nodeAggregateId, - ) { + ): self { return new self($contentRepositoryId, $workspaceName, $dimensionSpacePoint, $nodeAggregateId); } diff --git a/Neos.ContentRepositoryRegistry/Classes/NodeSerializer.php b/Neos.ContentRepositoryRegistry/Classes/NodeSerializer.php new file mode 100644 index 00000000000..431cb8555bc --- /dev/null +++ b/Neos.ContentRepositoryRegistry/Classes/NodeSerializer.php @@ -0,0 +1,59 @@ +contentRepositoryRegistry->get($identity->contentRepositoryId); + $workspace = $contentRepository->getWorkspaceFinder()->findOneByName($identity->workspaceName); + if (!$workspace) { + throw new \RuntimeException(sprintf('Workspace could not be found while deserializing node NodeIdentity<%s>.', json_encode($identity, JSON_PARTIAL_OUTPUT_ON_ERROR)), 1707757488); + } + $subgraph = $contentRepository->getContentGraph()->getSubgraph( + $workspace->currentContentStreamId, + $identity->dimensionSpacePoint, + // todo policy? Or what to prevent from accidentally showing unwanted nodes. + VisibilityConstraints::withoutRestrictions() + ); + $node = $subgraph->findNodeById($identity->nodeAggregateId); + if (!$node) { + throw new \RuntimeException(sprintf('NodeAggregateId could not be found while deserializing node NodeIdentity<%s>.', json_encode($identity, JSON_PARTIAL_OUTPUT_ON_ERROR)), 1707772263); + } + return $node; + } + + public function normalizeNodeToIdentity(Node $node): NodeIdentity + { + $contentRepository = $this->contentRepositoryRegistry->get($node->subgraphIdentity->contentRepositoryId); + $workspace = $contentRepository->getWorkspaceFinder()->findOneByCurrentContentStreamId($node->subgraphIdentity->contentStreamId); + if (!$workspace) { + throw new \RuntimeException(sprintf('Workspace could not be found for current content stream %s.', $node->subgraphIdentity->contentStreamId->value), 1707757787); + } + return NodeIdentity::create( + $node->subgraphIdentity->contentRepositoryId, + $workspace->workspaceName, + $node->subgraphIdentity->dimensionSpacePoint, + $node->nodeAggregateId + ); + } +}