Skip to content

Commit

Permalink
WIP: Adjust EventSourcedFrontendNodeRoutePartHandler to NodeIdentity
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Feb 16, 2024
1 parent 60705ce commit a90fddb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
Expand Up @@ -16,6 +16,7 @@

use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\SharedModel\Node\NodeIdentity;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Mvc\Routing\RoutingMiddleware;
Expand Down Expand Up @@ -44,14 +45,14 @@
/**
* A route part handler for finding nodes in the website's frontend. Like every RoutePartHandler,
* this handles both directions:
* - from URL to NodeAddress (via {@see EventSourcedFrontendNodeRoutePartHandler::matchWithParameters})
* - from NodeAddress to URL (via {@see EventSourcedFrontendNodeRoutePartHandler::resolveWithParameters})
* - from URL to NodeIdentity (via {@see EventSourcedFrontendNodeRoutePartHandler::matchWithParameters})
* - from NodeIdentity to URL (via {@see EventSourcedFrontendNodeRoutePartHandler::resolveWithParameters})
*
* For performance reasons, this uses a special projection {@see DocumentUriPathFinder}, and
* does NOT use the graph projection in any way.
*
*
* ## Match Direction (URL to NodeAddress)
* ## Match Direction (URL to NodeIdentity)
*
* This is usually simply triggered ONCE per request, before the controller starts working.
* The RoutePartHandler is invoked from {@see RoutingMiddleware} (which handles the routing).
Expand All @@ -62,7 +63,7 @@
* (*) = Extension Point ┌───────────────────────────────────────────────┐
* ┌──────────────┐ │ EventSourcedFrontendNodeRoutePartHandler │
* │SiteDetection │ │ ┌─────────────────────┐ │
* │Middleware (*)│────────────────────▶│ │DimensionResolver (*)│─────▶ Finding the ─┼─▶NodeAddress
* │Middleware (*)│────────────────────▶│ │DimensionResolver (*)│─────▶ Finding the ─┼─▶NodeIdentity
* └──────────────┘ current site │ └─────────────────────┘ NodeId │
* └───────────────────────────────────────────────┘
* current Content current
Expand Down Expand Up @@ -110,7 +111,7 @@
* ### Result of the Routing
*
* The **result** of the {@see EventSourcedFrontendNodeRoutePartHandler::matchWithParameters} call is a
* {@see NodeAddress} (wrapped in a {@see MatchResult}); so to build the NodeAddress, we need:
* {@see NodeIdentity} (wrapped in a {@see MatchResult}); so to build the NodeIdentity, we need:
* - the {@see WorkspaceName} (which is always **live** in our case)
* - the {@see ContentStreamId} of the Live workspace
* - The {@see DimensionSpacePoint} we want to see the page in (i.e. in language=de)
Expand All @@ -119,13 +120,13 @@
* - resolved by {@see EventSourcedFrontendNodeRoutePartHandler}
*
*
* ## Resolve Direction (NodeAddress to URL)
* ## Resolve Direction (NodeIdentity to URL)
*
* ```
* ┌────────────────────────────────────────────────────────────────────────┐
* │ EventSourcedFrontendNodeRoutePartHandler │
* │ ┌─────────────────────┐ ┌─────────────────────┐ │
* NodeAddress────┼▶ Finding the ────▶│ CrossSiteLinker (*) │─────▶│DimensionResolver (*)│─┼──▶ URL
* NodeIdentity───┼▶ Finding the ────▶│ CrossSiteLinker (*) │─────▶│DimensionResolver (*)│─┼──▶ URL
* │ URL └─────────────────────┘ └─────────────────────┘ │
* └────────────────────────────────────────────────────────────────────────┘
* ```
Expand Down Expand Up @@ -236,12 +237,13 @@ private function matchUriPath(
$uriPath,
$dimensionSpacePoint->hash
);
$nodeAddress = NodeAddressFactory::create($contentRepository)->createFromContentStreamIdAndDimensionSpacePointAndNodeAggregateId(
$documentUriPathFinder->getLiveContentStreamId(),
$nodeIdentity = NodeIdentity::create(
$contentRepository->id,
WorkspaceName::forLive(),
$dimensionSpacePoint,
$nodeInfo->getNodeAggregateId(),
);
return new MatchResult($nodeAddress->serializeForUri(), $nodeInfo->getRouteTags());
return new MatchResult($nodeIdentity->toJson(), $nodeInfo->getRouteTags());
}

/**
Expand All @@ -256,14 +258,13 @@ public function resolveWithParameters(array &$routeValues, RouteParameters $para
}
$currentRequestSiteDetectionResult = SiteDetectionResult::fromRouteParameters($parameters);

$nodeAddress = $routeValues[$this->name];
// TODO: for cross-CR links: NodeAddressInContentRepository as a new value object
if (!$nodeAddress instanceof NodeAddress) {
$nodeIdentity = $routeValues[$this->name];
if (!$nodeIdentity instanceof NodeIdentity) {
return false;
}

try {
$resolveResult = $this->resolveNodeAddress($nodeAddress, $currentRequestSiteDetectionResult);
$resolveResult = $this->resolveNodeIdentity($nodeIdentity, $currentRequestSiteDetectionResult);
} catch (NodeNotFoundException | InvalidShortcutException $exception) {
// TODO log exception
return false;
Expand All @@ -274,30 +275,26 @@ public function resolveWithParameters(array &$routeValues, RouteParameters $para
}

/**
* Resolves a node address for uri building.
* Resolves a node identity for uri building.
*
* NOTE: The resolving of nodes is also done for disabled/hidden nodes.
* To disallow showing a node actually disabled/hidden itself has to be ensured in matching a request path,
* not in building one.
*
* @param NodeAddress $nodeAddress
* @param SiteDetectionResult $currentRequestSiteDetectionResult
* @return ResolveResult
* @throws InvalidShortcutException
* @throws NodeNotFoundException
*/
private function resolveNodeAddress(
NodeAddress $nodeAddress,
private function resolveNodeIdentity(
NodeIdentity $nodeIdentity,
SiteDetectionResult $currentRequestSiteDetectionResult
): ResolveResult {
// TODO: SOMEHOW FIND OTHER CONTENT REPOSITORY HERE FOR CROSS-CR LINKS!!
$contentRepository = $this->contentRepositoryRegistry->get(
$currentRequestSiteDetectionResult->contentRepositoryId
$nodeIdentity->contentRepositoryId
);
$documentUriPathFinder = $contentRepository->projectionState(DocumentUriPathFinder::class);
$nodeInfo = $documentUriPathFinder->getByIdAndDimensionSpacePointHash(
$nodeAddress->nodeAggregateId,
$nodeAddress->dimensionSpacePoint->hash
$nodeIdentity->nodeAggregateId,
$nodeIdentity->dimensionSpacePoint->hash
);

if ($nodeInfo->isShortcut()) {
Expand All @@ -322,7 +319,7 @@ private function resolveNodeAddress(
}

$uriConstraints = $this->delegatingResolver->fromDimensionSpacePointToUriConstraints(
$nodeAddress->dimensionSpacePoint,
$nodeIdentity->dimensionSpacePoint,
$nodeInfo,
$targetSite,
$uriConstraints
Expand Down
Expand Up @@ -20,8 +20,6 @@
* Marker interface which can be used to replace the currently used FrontendNodeRoutePartHandler,
* to e.g. use the one with localization support.
*
* TODO CORE MIGRATION
*
* **See {@see EventSourcedFrontendNodeRoutePartHandler} documentation for a
* detailed explanation of the Frontend Routing process.**
*/
Expand Down

0 comments on commit a90fddb

Please sign in to comment.