diff --git a/src/lib/Repository/NameSchema/NameSchemaService.php b/src/lib/Repository/NameSchema/NameSchemaService.php index 8554f24f1a..2e02747ffe 100644 --- a/src/lib/Repository/NameSchema/NameSchemaService.php +++ b/src/lib/Repository/NameSchema/NameSchemaService.php @@ -83,7 +83,9 @@ public function resolveUrlAliasSchema(Content $content, ContentType $contentType { $contentType ??= $content->getContentType(); $schemaName = $contentType->urlAliasSchema ?: $contentType->nameSchema; + [$filteredNameSchema, $groupLookupTable] = $this->filterNameSchema($schemaName); $schemaIdentifiers = $this->schemaIdentifierExtractor->extract($schemaName); + $tokens = $this->extractTokens($filteredNameSchema); /** @var \Ibexa\Contracts\Core\Event\ResolveUrlAliasSchemaEvent $event */ $event = $this->eventDispatcher->dispatch( @@ -92,17 +94,17 @@ public function resolveUrlAliasSchema(Content $content, ContentType $contentType $content ) ); - $names = []; - $tokens = $event->getTokenValues(); - $extractedTokens = $this->extractTokens($schemaName); - foreach ($tokens as $languageCode => $tokenValues) { - $schema = $schemaName; - foreach ($extractedTokens as $extractedToken) { - $name = $this->resolveToken($extractedToken, $tokenValues, []); - $schema = str_replace($extractedToken, $name, $schema); + $tokenValues = $event->getTokenValues(); + foreach ($tokenValues as $languageCode => $tokenValue) { + $name = $filteredNameSchema; + foreach ($tokens as $token) { + $string = $this->resolveToken($token, $tokenValue, $groupLookupTable); + $name = str_replace($token, $string, $name); } - $names[$languageCode] = $schema; + $name = $this->validateNameLength($name); + + $names[$languageCode] = $name; } return $names; diff --git a/tests/lib/Repository/NameSchema/SchemaIdentifierExtractorTest.php b/tests/lib/Repository/NameSchema/SchemaIdentifierExtractorTest.php index bf60625f60..e40378ba0e 100644 --- a/tests/lib/Repository/NameSchema/SchemaIdentifierExtractorTest.php +++ b/tests/lib/Repository/NameSchema/SchemaIdentifierExtractorTest.php @@ -76,6 +76,15 @@ public function getDataForTestExtract(): iterable 'custom' => ['bar'], ], ]; + + $schemaString = ' )-()-'; + yield $schemaString => [ + $schemaString, + [ + 'field' => ['specification', 'name', 'image1', 'baz', 'bar'], + 'custom' => ['bar'], + ], + ]; } protected function setUp(): void