From 65f6330de424617aead3db283a519d07d1ec3854 Mon Sep 17 00:00:00 2001 From: Bernhard Schmitt Date: Thu, 15 Aug 2024 21:25:44 +0200 Subject: [PATCH] Adjust to Neos 9 beta 11 --- ...ractComponentPresentationObjectFactory.php | 16 ++++++++++++ Classes/Infrastructure/UriService.php | 26 +++++-------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Classes/Fusion/AbstractComponentPresentationObjectFactory.php b/Classes/Fusion/AbstractComponentPresentationObjectFactory.php index 54d9293..86ae490 100644 --- a/Classes/Fusion/AbstractComponentPresentationObjectFactory.php +++ b/Classes/Fusion/AbstractComponentPresentationObjectFactory.php @@ -8,11 +8,13 @@ namespace PackageFactory\AtomicFusion\PresentationObjects\Fusion; +use Neos\ContentRepository\Core\NodeType\NodeType; use Neos\ContentRepository\Core\Projection\ContentGraph\Node; use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; use Neos\Eel\ProtectedContextAwareInterface; use Neos\Flow\Annotations as Flow; use Neos\Flow\I18n\Translator; +use Neos\Neos\Domain\NodeLabel\NodeLabelGeneratorInterface; /** * The generic abstract component presentation object factory implementation @@ -30,6 +32,20 @@ abstract class AbstractComponentPresentationObjectFactory implements #[Flow\Inject] protected Translator $translator; + #[Flow\Inject] + protected NodeLabelGeneratorInterface $nodeLabelGenerator; + + final protected function getNodeType(Node $node): ?NodeType + { + return $this->contentRepositoryRegistry->get($node->contentRepositoryId) + ->getNodeTypeManager()->getNodeType($node->nodeTypeName); + } + + final protected function getNodeLabel(Node $node): string + { + return $this->nodeLabelGenerator->getLabel($node); + } + /** * @template T * @param class-string $expectedType diff --git a/Classes/Infrastructure/UriService.php b/Classes/Infrastructure/UriService.php index 3986248..6675f41 100644 --- a/Classes/Infrastructure/UriService.php +++ b/Classes/Infrastructure/UriService.php @@ -12,20 +12,18 @@ use GuzzleHttp\Psr7\Uri; use Neos\ContentRepository\Core\Projection\ContentGraph\ContentSubgraphInterface; use Neos\ContentRepository\Core\Projection\ContentGraph\Node; +use Neos\ContentRepository\Core\SharedModel\Node\NodeAddress; use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; -use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; use Neos\Flow\Annotations as Flow; use Neos\Flow\Mvc\Controller\ControllerContext; -use Neos\Flow\Mvc\Routing\UriBuilder; use Neos\Flow\ResourceManagement\PersistentResource; use Neos\Flow\ResourceManagement\ResourceManager; use Neos\Flow\Http; use Neos\Media\Domain\Model\AssetInterface; use Neos\Media\Domain\Repository\AssetRepository; -use Neos\Neos\FrontendRouting\NodeAddressFactory; -use Neos\Neos\FrontendRouting\NodeUriBuilder; use Neos\Flow\Mvc; use Neos\Flow\Core\Bootstrap; +use Neos\Neos\FrontendRouting\NodeUriBuilderFactory; use PackageFactory\AtomicFusion\PresentationObjects\Fusion\UriServiceInterface; use Psr\Http\Message\UriInterface; @@ -38,29 +36,17 @@ final class UriService implements UriServiceInterface private ?ControllerContext $controllerContext = null; public function __construct( - private readonly ContentRepositoryRegistry $contentRepositoryRegistry, private readonly ResourceManager $resourceManager, private readonly AssetRepository $assetRepository, - private readonly Bootstrap $bootstrap + private readonly Bootstrap $bootstrap, + private readonly NodeUriBuilderFactory $nodeUriBuilderFactory, ) { } public function getNodeUri(Node $documentNode, bool $absolute = false, ?string $format = null): UriInterface { - $contentRepository = $this->contentRepositoryRegistry->get( - $documentNode->subgraphIdentity->contentRepositoryId - ); - $nodeAddressFactory = NodeAddressFactory::create($contentRepository); - $nodeAddress = $nodeAddressFactory->createFromNode($documentNode); - - $uriBuilder = new UriBuilder(); - $uriBuilder->setRequest($this->getControllerContext()->getRequest()); - $uriBuilder - ->setCreateAbsoluteUri($absolute) - ->setFormat($format ?: 'html'); - - return NodeUriBuilder::fromUriBuilder($uriBuilder) - ->uriFor($nodeAddress); + return $this->nodeUriBuilderFactory->forActionRequest($this->getControllerContext()->getRequest()) + ->uriFor(NodeAddress::fromNode($documentNode)); } public function getResourceUri(string $packageKey, string $resourcePath): UriInterface