-
Notifications
You must be signed in to change notification settings - Fork 17
IBX-5630: Added possibility to extend URL schema resolving #242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
595ae45
IBX-5630
kisztof 093436e
more readabillity
kisztof 635cbac
Fixed extension point
kisztof 368e7c3
Fixed priority
kisztof 0228b20
Refactored NameSchemaSubscriber
kisztof e7c1a20
Fixed url schema generation
kisztof 7a58566
Ref
kisztof 25602ff
Defined NameSchemaService as DIC Service
alongosz 8de80e4
Fixed some tests
kisztof 0280c6d
Fixed content name generation
kisztof 9723018
Test fix
kisztof af1ccf8
Fix tests
kisztof 9877d12
Fixed minor issues in NameSchemaSubscriber
alongosz 097cc11
Restored original Helper\NameSchemaService::resolveUrlAliasSchema for BC
alongosz 04db1ed
[CS] Fixed minor issue in NameSchemaService::resolve method
alongosz f8e9b24
Refactored NameSchemaService to be more lightweight
alongosz 08591ee
[Tests] Defined URLAliasService and required ibexa.kernel.root_dir param
alongosz 2b7c600
[Tests] Created abstract RepositoryTestCase for integration tests
alongosz f8d46be
[Tests] Unified SF EventDispatcher definition for Legacy integration
alongosz cbb6453
[Tests] Added coverage for URLAliasService::lookup using IbexaKernelT…
alongosz ff73ed4
[Tests] Added coverage for SchemaIdentifierExtractor
alongosz 2524a58
[Tests] Refactored tests to avoid comparing proxies
alongosz d8321a9
[Tests] Revamped NameSchemaService unit test
alongosz 8009aca
fixup! [Tests] Revamped NameSchemaService unit test
alongosz 2992a36
Fixed field name generator
kisztof e066bd3
Fixed codesmells
kisztof c31d9f9
Fixed SchemaIdentifierExtractor
kisztof 651c580
Fixed the issue when fielddefinition not found
kisztof 1503ec9
Applied CR
kisztof 8c57681
Added missing return type
kisztof e7e5f73
Improved NameSchemaService test
kisztof 9da8532
Fixes Applied
kisztof 595532b
Made NameSchemaServiceTest class final
kisztof 3fb0761
[Tests] Refactored NameSchemaServiceTest to avoid code duplication
alongosz 4375c0d
Fixed CR issues
kisztof ac18a71
Fixed an issue with grouping
kisztof 96020b1
Fixed issue with grouping
kisztof File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <?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\Contracts\Core\Event; | ||
|
|
||
| use Ibexa\Contracts\Core\Repository\Values\Content\Content; | ||
| use Symfony\Contracts\EventDispatcher\Event; | ||
|
|
||
| final class ResolveUrlAliasSchemaEvent extends Event | ||
| { | ||
| /** @var array<string, array> */ | ||
| private array $schemaIdentifiers; | ||
|
|
||
| private Content $content; | ||
|
|
||
| /** | ||
| * @var array<string, array<string>> | ||
| */ | ||
| private array $names = []; | ||
|
|
||
| public function __construct( | ||
| array $schemaIdentifiers, | ||
| Content $content | ||
| ) { | ||
| $this->schemaIdentifiers = $schemaIdentifiers; | ||
| $this->content = $content; | ||
| } | ||
|
|
||
| public function getSchemaIdentifiers(): array | ||
| { | ||
| return $this->schemaIdentifiers; | ||
| } | ||
|
|
||
| public function getContent(): Content | ||
| { | ||
| return $this->content; | ||
| } | ||
|
|
||
| public function getTokenValues(): array | ||
| { | ||
| return $this->names; | ||
| } | ||
|
|
||
| public function setTokenValues(array $names): void | ||
| { | ||
| $this->names = $names; | ||
| } | ||
| } | ||
50 changes: 50 additions & 0 deletions
50
src/contracts/Repository/NameSchema/NameSchemaServiceInterface.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <?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\Contracts\Core\Repository\NameSchema; | ||
|
|
||
| use Ibexa\Contracts\Core\Repository\Values\Content\Content; | ||
| use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType; | ||
|
|
||
| /** | ||
| * @internal Meant to be used by 1st party only | ||
| * | ||
| * @experimental | ||
| */ | ||
| interface NameSchemaServiceInterface | ||
| { | ||
| /** | ||
| * @return array<string, string> key value map of names for a language code | ||
| */ | ||
| public function resolveUrlAliasSchema(Content $content, ContentType $contentType = null): array; | ||
|
|
||
| /** | ||
| * @param array<string, array<string, string>> $fieldMap | ||
| * @param array<string> $languageCodes | ||
| * | ||
| * @return array | ||
| */ | ||
| public function resolveNameSchema( | ||
| Content $content, | ||
| array $fieldMap = [], | ||
| array $languageCodes = [], | ||
| ContentType $contentType = null | ||
| ): array; | ||
|
|
||
| /** | ||
| * Returns the real name for a content name pattern. | ||
| * | ||
| * @param array<string, array<string, string>> $fieldMap | ||
| * @param array<string> $languageCodes | ||
| * | ||
| * @return array<string> | ||
| * | ||
| * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException | ||
| */ | ||
| public function resolve(string $nameSchema, ContentType $contentType, array $fieldMap, array $languageCodes): array; | ||
kisztof marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
17 changes: 17 additions & 0 deletions
17
src/contracts/Repository/NameSchema/SchemaIdentifierExtractorInterface.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?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\Contracts\Core\Repository\NameSchema; | ||
|
|
||
| interface SchemaIdentifierExtractorInterface | ||
| { | ||
| /** | ||
| * @return array<string, array<string, string>> | ||
| */ | ||
| public function extract(string $schemaString): array; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/lib/Repository/EventSubscriber/NameSchemaSubscriber.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| <?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\EventSubscriber; | ||
|
|
||
| use Ibexa\Contracts\Core\Event\ResolveUrlAliasSchemaEvent; | ||
| use Ibexa\Core\FieldType\FieldTypeRegistry; | ||
| use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
|
||
| /** | ||
| * @internal | ||
| */ | ||
| final class NameSchemaSubscriber implements EventSubscriberInterface | ||
alongosz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| private FieldTypeRegistry $fieldTypeRegistry; | ||
|
|
||
| public function __construct(FieldTypeRegistry $fieldTypeRegistry) | ||
| { | ||
| $this->fieldTypeRegistry = $fieldTypeRegistry; | ||
| } | ||
|
|
||
| public static function getSubscribedEvents(): array | ||
| { | ||
| return [ | ||
| ResolveUrlAliasSchemaEvent::class => [ | ||
| ['onResolveUrlAliasSchema', -100], | ||
| ], | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Resolves the URL alias schema by setting token values for specified field identifiers and languages. | ||
| * | ||
| * @param \Ibexa\Contracts\Core\Event\ResolveUrlAliasSchemaEvent $event | ||
| */ | ||
| public function onResolveUrlAliasSchema(ResolveUrlAliasSchemaEvent $event): void | ||
| { | ||
| if (!array_key_exists('field', $event->getSchemaIdentifiers())) { | ||
| return; | ||
| } | ||
|
|
||
| $content = $event->getContent(); | ||
| $identifiers = $event->getSchemaIdentifiers()['field']; | ||
| $languages = $event->getContent()->getVersionInfo()->getLanguages(); | ||
| $tokenValues = $event->getTokenValues(); | ||
|
|
||
| $contentType = $content->getContentType(); | ||
| foreach ($languages as $language) { | ||
| $languageCode = $language->getLanguageCode(); | ||
| foreach ($identifiers as $identifier) { | ||
| $fieldDefinition = $contentType->getFieldDefinition($identifier); | ||
| if (null === $fieldDefinition) { | ||
| continue; | ||
| } | ||
| $persistenceFieldType = $this->fieldTypeRegistry->getFieldType($fieldDefinition->fieldTypeIdentifier); | ||
|
|
||
| $fieldValue = $content->getFieldValue($identifier, $languageCode); | ||
| $fieldValue = $persistenceFieldType->getName( | ||
| $fieldValue, | ||
| $fieldDefinition, | ||
| $languageCode | ||
| ); | ||
|
|
||
| $tokenValues[$languageCode][$identifier] = $fieldValue; | ||
| } | ||
| } | ||
|
|
||
| $event->setTokenValues($tokenValues); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.