I wouldn’t call it a bug, but it just took me some time to figure out why my redirect after login created strange URLs, so I’d like to discuss it here.
I have a multi language setup with fallbacks (Default language is German and then there is also French with a fallback to German). Now there is a login and after the login I want to redirect the user to a node (which depends on the role) in the language s/he defined in the preferences.
protected function onAuthenticationSuccess(ActionRequest $originalRequest = null) {
...
$landingNode = $this->startNodeService->getStartNodeForUser($currentUser);
$this->redirectToUri($this->linkingService->createNodeUri($this->controllerContext, $landingNode));
}
and the StartNodeService does
public function getStartNodeForUser(User $user){
...
$context = $this->contextFactory->create(['dimensions' => ['language' => [$languagePreference]]]);
$nodeData = $this->nodeDataRepository->findOneByIdentifier($nodeIdentifier, $context->getWorkspace(), $context->getDimensions());
return $nodeData ? $this->nodeFactory->createFromNodeData($nodeData, $context) : null;
}
with $languagePreference = ‘fr’ this returns the French node, but when I pass it to createNodeUri I get “de/page-francaise”… what I have to do to get “fr/page-francaise” is passing also the fallback dimension value to the contextFactory
$context = $this->contextFactory->create(['dimensions' => ['language' => [$languagePreference, 'de']]]);
because deep down in Neos\Neos\Routing\FrontendNodeRoutePartHandler->getUriSegmentForDimensions()
it calls Neos\ContentRepository\Domain\Service->findPresetByDimensionValues()
which matches the preset ‘fr’ only when all the fallback values [‘fr’, ‘de’] are present. when I just pass [‘fr’] it takes the default preset ‘de’ with the uriSegment ‘de’
long story short, is there a reason why Neos doesn’t provide a function to get a node (and node uri) by preset? Or is there already a Service for that and I’m just doing it too complicated?