diff --git a/src/lib/Repository/EventSubscriber/NameSchemaSubscriber.php b/src/lib/Repository/EventSubscriber/NameSchemaSubscriber.php index befa7e238d..69d12ac60c 100644 --- a/src/lib/Repository/EventSubscriber/NameSchemaSubscriber.php +++ b/src/lib/Repository/EventSubscriber/NameSchemaSubscriber.php @@ -14,6 +14,7 @@ use Ibexa\Contracts\Core\Event\NameSchema\ResolveNameSchemaEvent; use Ibexa\Contracts\Core\Event\NameSchema\ResolveUrlAliasSchemaEvent; use Ibexa\Contracts\Core\Repository\Values\Content\Content; +use Ibexa\Contracts\Core\Repository\Values\Content\Language; use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType; use Ibexa\Core\FieldType\FieldTypeRegistry; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -64,7 +65,12 @@ public function onResolveUrlAliasSchema(ResolveUrlAliasSchemaEvent $event): void $content = $event->getContent(); $contentType = $content->getContentType(); $tokenValues = $this->processEvent( - $event->getContent()->getVersionInfo()->getLanguages(), + array_map( + static function (Language $language) { + return $language->getLanguageCode(); + }, + $event->getContent()->getVersionInfo()->getLanguages() + ), $event->getSchemaIdentifiers()['field'], $contentType, $content, @@ -97,6 +103,11 @@ private function processNameSchemaEvent(AbstractNameSchemaEvent $event): void $event->setTokenValues($tokenValues); } + /** + * @param array $languages + * @param array> $identifiers + * @param array> $tokenValues + */ private function processEvent( array $languages, array $identifiers, @@ -105,9 +116,9 @@ private function processEvent( array $tokenValues, ?array $fieldMap = null ): array { - foreach ($languages as $language) { - $languageCode = is_string($language) ? $language : $language->getLanguageCode(); + foreach ($languages as $languageCode) { foreach ($identifiers as $identifier) { + $tokenValues[$languageCode] = []; $fieldDefinition = $contentType->getFieldDefinition($identifier); if (null === $fieldDefinition) { continue; diff --git a/src/lib/Repository/NameSchema/NameSchemaService.php b/src/lib/Repository/NameSchema/NameSchemaService.php index 89bbe32ef8..8e1d4becc3 100644 --- a/src/lib/Repository/NameSchema/NameSchemaService.php +++ b/src/lib/Repository/NameSchema/NameSchemaService.php @@ -274,6 +274,10 @@ protected function filterNameSchema(string $nameSchema): array */ public function buildNames(array $tokenValues, string $nameSchema): array { + if (empty($tokenValues)) { + throw new UnresolvedTokenNamesException(); + } + [$filteredNameSchema, $groupLookupTable] = $this->filterNameSchema($nameSchema); $tokens = $this->extractTokens($filteredNameSchema); diff --git a/src/lib/Repository/NameSchema/UnresolvedTokenNamesException.php b/src/lib/Repository/NameSchema/UnresolvedTokenNamesException.php new file mode 100644 index 0000000000..b5db688671 --- /dev/null +++ b/src/lib/Repository/NameSchema/UnresolvedTokenNamesException.php @@ -0,0 +1,15 @@ +