diff --git a/Neos.Neos/Classes/TypeConverter/HackyNodeAddressToNodeConverter.php b/Neos.Neos/Classes/TypeConverter/HackyNodeAddressToNodeConverter.php new file mode 100644 index 00000000000..0774063b2a5 --- /dev/null +++ b/Neos.Neos/Classes/TypeConverter/HackyNodeAddressToNodeConverter.php @@ -0,0 +1,94 @@ + + */ + protected $sourceTypes = ['string']; + + /** + * @var string + */ + protected $targetType = Node::class; + + /** + * @var integer + */ + protected $priority = 2; + + #[Flow\Inject] + protected ContentRepositoryRegistry $contentRepositoryRegistry; + #[Flow\Inject] + protected Bootstrap $bootstrap; + + /** + * @param string $source + * @param string $targetType + * @param array $subProperties + * @return ?Node + */ + public function convertFrom( + $source, + $targetType = null, + array $subProperties = [], + PropertyMappingConfigurationInterface $configuration = null + ) { + $activeRequestHandler = $this->bootstrap->getActiveRequestHandler(); + $contentRepositoryId = ContentRepositoryId::fromString('default'); + if ($activeRequestHandler instanceof RequestHandler) { + $httpRequest = $activeRequestHandler->getHttpRequest(); + $siteDetectionResult = SiteDetectionResult::fromRequest($httpRequest); + $contentRepositoryId = $siteDetectionResult->contentRepositoryId; + } + + $contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId); + $nodeAddressFactory = NodeAddressFactory::create($contentRepository); + $nodeAddress = $nodeAddressFactory->createFromUriString($source); + + $subgraph = $contentRepository->getContentGraph() + ->getSubgraph( + $nodeAddress->contentStreamId, + $nodeAddress->dimensionSpacePoint, + $nodeAddress->isInLiveWorkspace() + ? VisibilityConstraints::frontend() + : VisibilityConstraints::withoutRestrictions() + ); + + return $subgraph->findNodeById($nodeAddress->nodeAggregateId); + } +} diff --git a/Neos.Neos/Classes/TypeConverter/NodeToNodeAddressStringConverter.php b/Neos.Neos/Classes/TypeConverter/NodeToNodeAddressStringConverter.php new file mode 100644 index 00000000000..716499b8b7d --- /dev/null +++ b/Neos.Neos/Classes/TypeConverter/NodeToNodeAddressStringConverter.php @@ -0,0 +1,72 @@ + + */ + protected $sourceTypes = [Node::class]; + + /** + * @var string + */ + protected $targetType = 'string'; + + /** + * @var integer + */ + protected $priority = 1; + + /** + * @param Node $source + * @param string $targetType + * @param array $subProperties + * @return mixed|\Neos\Error\Messages\Error|string|null + */ + public function convertFrom( + $source, + $targetType = null, + array $subProperties = [], + PropertyMappingConfigurationInterface $configuration = null + ) { + $contentRepository = $this->contentRepositoryRegistry->get( + $source->subgraphIdentity->contentRepositoryId + ); + return NodeAddressFactory::create($contentRepository)->createFromNode($source)->serializeForUri(); + } +}