Skip to content

Commit

Permalink
Added language mapping. Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kisztof committed Aug 17, 2023
1 parent c13ee03 commit 0bc36a4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/lib/Repository/EventSubscriber/NameSchemaSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -97,6 +103,11 @@ private function processNameSchemaEvent(AbstractNameSchemaEvent $event): void
$event->setTokenValues($tokenValues);
}

/**
* @param array<string> $languages
* @param array<string<array<string>> $identifiers
* @param array<string<array<string>> $tokenValues
*/
private function processEvent(
array $languages,
array $identifiers,
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/lib/Repository/NameSchema/NameSchemaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
15 changes: 15 additions & 0 deletions src/lib/Repository/NameSchema/UnresolvedTokenNamesException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Core\Repository\NameSchema;

use LogicException;

final class UnresolvedTokenNamesException extends LogicException
{
}

0 comments on commit 0bc36a4

Please sign in to comment.