Skip to content

Commit

Permalink
Merge pull request #4329 from neos/zeroDimensionalUriPaths
Browse files Browse the repository at this point in the history
BUGFIX: Zero dimensional uri paths
  • Loading branch information
nezaniel authored Jun 28, 2023
2 parents 37e31aa + 0d2b80b commit 35bc7f7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
use Neos\Neos\FrontendRouting\DimensionResolution\Resolver\UriPathResolver\Segments;
use Neos\Neos\FrontendRouting\DimensionResolution\Resolver\UriPathResolver\Separator;


/**
* @api
*/
Expand All @@ -50,33 +49,35 @@ public function create(
->getContentDimensionSource()
->getContentDimensionsOrderedByPriority();

if (count($contentDimensions) >= 2) {
throw new AutoUriPathResolverConfigurationException(
'The AutoUriPathResolverFactory is only meant for single-dimension use cases.'
. ' For everything more advanced, please manually configure UriPathResolver in Settings.yaml.'
);
}
switch (count($contentDimensions)) {
case 0:
return UriPathResolver::createForNoDimensions();
case 1:
$contentDimension = reset($contentDimensions);
assert($contentDimension instanceof ContentDimension);
$mapping = [];
foreach ($contentDimension->values as $value) {
// we'll take the Dimension Value as Uri Path Segment value.
$mapping[] = SegmentMappingElement::create($value, $value->value);
}

$contentDimension = reset($contentDimensions);
assert($contentDimension instanceof ContentDimension);
$mapping = [];
foreach ($contentDimension->values as $value) {
// we'll take the Dimension Value as Uri Path Segment value.
$mapping[] = SegmentMappingElement::create($value, $value->value);
$segments = Segments::create(
Segment::create(
$contentDimension->id,
SegmentMapping::create(...$mapping)
)
);
return UriPathResolver::create(
$segments,
Separator::fromString('-'),
$contentRepository->getContentDimensionSource(),
$siteConfiguration->defaultDimensionSpacePoint
);
default:
throw new AutoUriPathResolverConfigurationException(
'The AutoUriPathResolverFactory is only meant for single-dimension use cases.'
. ' For everything more advanced, please manually configure UriPathResolver in Settings.yaml.'
);
}

$segments = Segments::create(
Segment::create(
$contentDimension->id,
SegmentMapping::create(...$mapping)
)
);

return UriPathResolver::create(
$segments,
Separator::fromString('-'),
$contentRepository->getContentDimensionSource(),
$siteConfiguration->defaultDimensionSpacePoint
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ public static function create(
);
}

public static function createForNoDimensions(): self
{
return new self(
[],
[],
Segments::create(),
DimensionSpacePoint::fromArray([])
);
}

private static function validate(
Segments $segments,
Separator $separator,
Expand Down

0 comments on commit 35bc7f7

Please sign in to comment.