-
Notifications
You must be signed in to change notification settings - Fork 17
IBX-10936: Implemented fetching field definitions from an expression #1765
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
Open
barw4
wants to merge
10
commits into
4.6
Choose a base branch
from
expression-parser-endpoint
base: 4.6
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5c7fa4d
IBX-9266: Implemented fetching field definitions from an expression
barw4 5878051
IBX-9266: Review remarks
barw4 0c061d9
IBX-10936: Fix circular dependency
barw4 a8fb412
IBX-10936: Applied review remark
barw4 0e365cc
IBX-10936: Add expression parser configuration
barw4 02b9841
IBX-10936: Add tests
barw4 2f9e428
IBX-10936: Review remark
barw4 5ba599b
IBX-10936: Naming
barw4 1e34a5e
IBX-10936: CS
barw4 d9f5084
IBX-10936: Fixup
barw4 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/bundle/Controller/ContentTypeFieldsByExpressionController.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,52 @@ | ||
| <?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\Bundle\AdminUi\Controller; | ||
|
|
||
| use Ibexa\AdminUi\Exception\FieldTypeExpressionParserException; | ||
| use Ibexa\AdminUi\REST\Value\ContentType\FieldDefinitionInfoList; | ||
| use Ibexa\Contracts\AdminUi\ContentType\ContentTypeFieldsByExpressionServiceInterface; | ||
| use Ibexa\Rest\Message; | ||
| use Ibexa\Rest\Server\Controller as RestController; | ||
| use Ibexa\Rest\Server\Exceptions\BadRequestException; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
|
|
||
| final class ContentTypeFieldsByExpressionController extends RestController | ||
| { | ||
| private ContentTypeFieldsByExpressionServiceInterface $fieldsByExpressionService; | ||
|
|
||
| public function __construct(ContentTypeFieldsByExpressionServiceInterface $fieldsByExpressionService) | ||
| { | ||
| $this->fieldsByExpressionService = $fieldsByExpressionService; | ||
| } | ||
|
|
||
| /** | ||
| * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException | ||
| */ | ||
| public function loadFieldDefinitionsFromExpression(Request $request): FieldDefinitionInfoList | ||
| { | ||
| /** @var \Ibexa\AdminUi\REST\Value\ContentType\FieldDefinitionExpression $input */ | ||
| $input = $this->inputDispatcher->parse( | ||
| new Message( | ||
| ['Content-Type' => $request->headers->get('Content-Type')], | ||
| $request->getContent() | ||
| ) | ||
| ); | ||
|
|
||
| try { | ||
| $fieldDefinitions = $this->fieldsByExpressionService->getFieldsFromExpression( | ||
| $input->expression, | ||
| $input->configuration, | ||
| ); | ||
| } catch (FieldTypeExpressionParserException $e) { | ||
| throw new BadRequestException($e->getMessage(), $e->getCode(), $e); | ||
| } | ||
|
|
||
| return new FieldDefinitionInfoList($fieldDefinitions); | ||
| } | ||
| } |
66 changes: 66 additions & 0 deletions
66
src/bundle/DependencyInjection/Configuration/Parser/ContentTypeFieldsByExpression.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,66 @@ | ||
| <?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\Bundle\AdminUi\DependencyInjection\Configuration\Parser; | ||
|
|
||
| use Ibexa\Bundle\Core\DependencyInjection\Configuration\AbstractParser; | ||
| use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface; | ||
| use Symfony\Component\Config\Definition\Builder\NodeBuilder; | ||
|
|
||
| /** | ||
| * Configuration parser for mapping content type fields expressions. | ||
| * | ||
| * Example configuration: | ||
| * | ||
| * ```yaml | ||
| * ibexa: | ||
| * system: | ||
| * default: | ||
| * content_type_field_type_groups: | ||
| * configurations: | ||
| * vectorizable_fields: [ezstring, eztext] | ||
| * ``` | ||
| */ | ||
| final class ContentTypeFieldsByExpression extends AbstractParser | ||
| { | ||
| public function addSemanticConfig(NodeBuilder $nodeBuilder): void | ||
| { | ||
| $nodeBuilder | ||
| ->arrayNode('content_type_field_type_groups') | ||
| ->addDefaultsIfNotSet() | ||
| ->children() | ||
| ->arrayNode('configurations') | ||
| ->useAttributeAsKey('name') | ||
| ->arrayPrototype() | ||
| ->scalarPrototype()->end() | ||
| ->end() | ||
| ->defaultValue([]) | ||
| ->end() | ||
| ->end() | ||
| ->end(); | ||
| } | ||
|
|
||
| /** | ||
| * @param array<string,mixed> $scopeSettings | ||
| */ | ||
| public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer): void | ||
| { | ||
| if (!isset($scopeSettings['content_type_field_type_groups'])) { | ||
| return; | ||
| } | ||
|
|
||
| $configurations = $scopeSettings['content_type_field_type_groups']['configurations'] ?? []; | ||
| foreach ($configurations as $name => $config) { | ||
| $contextualizer->setContextualParameter( | ||
| "content_type_field_type_groups.configurations.$name", | ||
| $currentScope, | ||
| $config | ||
| ); | ||
| } | ||
| } | ||
| } |
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
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
28 changes: 28 additions & 0 deletions
28
src/lib/REST/Input/Parser/ContentType/FieldDefinitionExpression.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,28 @@ | ||
| <?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\AdminUi\REST\Input\Parser\ContentType; | ||
|
|
||
| use Ibexa\AdminUi\REST\Value\ContentType\FieldDefinitionExpression as FieldDefinitionExpressionValue; | ||
| use Ibexa\Contracts\Rest\Exceptions; | ||
| use Ibexa\Contracts\Rest\Input\ParsingDispatcher; | ||
| use Ibexa\Rest\Input\BaseParser; | ||
|
|
||
| final class FieldDefinitionExpression extends BaseParser | ||
| { | ||
| public function parse(array $data, ParsingDispatcher $parsingDispatcher): FieldDefinitionExpressionValue | ||
| { | ||
| if (!array_key_exists('expression', $data) || !is_string($data['expression'])) { | ||
| throw new Exceptions\Parser( | ||
| sprintf("Missing or invalid 'expression' property for %s.", FieldDefinitionExpressionValue::class) | ||
| ); | ||
| } | ||
|
|
||
| return new FieldDefinitionExpressionValue($data['expression'], $data['configuration'] ?? null); | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
src/lib/REST/Output/ValueObjectVisitor/ContentType/FieldDefinitionInfoList.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,43 @@ | ||
| <?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\AdminUi\REST\Output\ValueObjectVisitor\ContentType; | ||
|
|
||
| use Ibexa\Contracts\Rest\Output\Generator; | ||
| use Ibexa\Contracts\Rest\Output\Visitor; | ||
| use Ibexa\Rest\Server\Output\ValueObjectVisitor\RestContentTypeBase; | ||
|
|
||
| final class FieldDefinitionInfoList extends RestContentTypeBase | ||
| { | ||
| /** | ||
| * @param \Ibexa\AdminUi\REST\Value\ContentType\FieldDefinitionInfoList $data | ||
| */ | ||
| public function visit(Visitor $visitor, Generator $generator, $data): void | ||
| { | ||
| $fieldDefinitionList = $data; | ||
|
|
||
| $generator->startObjectElement('FieldDefinitions', 'FieldDefinitionInfoList'); | ||
| $visitor->setHeader('Content-Type', $generator->getMediaType('FieldDefinitionInfoList')); | ||
|
|
||
| $generator->startList('FieldDefinitionInfo'); | ||
| foreach ($fieldDefinitionList->fieldDefinitions as $fieldDefinition) { | ||
| $generator->startObjectElement('FieldDefinitionInfo'); | ||
|
|
||
| $generator->valueElement('id', $fieldDefinition->id); | ||
| $generator->valueElement('identifier', $fieldDefinition->identifier); | ||
| $generator->valueElement('position', $fieldDefinition->position); | ||
|
|
||
| $this->visitNamesList($generator, $fieldDefinition->getNames()); | ||
|
|
||
| $generator->endObjectElement('FieldDefinitionInfo'); | ||
| } | ||
| $generator->endList('FieldDefinitionInfo'); | ||
|
|
||
| $generator->endObjectElement('FieldDefinitions'); | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
src/lib/REST/Value/ContentType/FieldDefinitionExpression.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,24 @@ | ||
| <?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\AdminUi\REST\Value\ContentType; | ||
|
|
||
| use Ibexa\Rest\Value as RestValue; | ||
|
|
||
| final class FieldDefinitionExpression extends RestValue | ||
| { | ||
| public string $expression; | ||
Steveb-p marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public ?string $configuration = null; | ||
|
|
||
| public function __construct(string $expression, ?string $configuration = null) | ||
| { | ||
| $this->expression = $expression; | ||
| $this->configuration = $configuration; | ||
| } | ||
| } | ||
25 changes: 25 additions & 0 deletions
25
src/lib/REST/Value/ContentType/FieldDefinitionInfoList.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,25 @@ | ||
| <?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\AdminUi\REST\Value\ContentType; | ||
|
|
||
| use Ibexa\Rest\Value as RestValue; | ||
|
|
||
| final class FieldDefinitionInfoList extends RestValue | ||
| { | ||
| /** @var \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition[] */ | ||
| public array $fieldDefinitions; | ||
|
|
||
| /** | ||
| * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition[] $fieldDefinitions | ||
| */ | ||
| public function __construct(array $fieldDefinitions) | ||
| { | ||
| $this->fieldDefinitions = $fieldDefinitions; | ||
| } | ||
| } |
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 | ||
|---|---|---|---|---|
|
|
@@ -14,6 +14,8 @@ interface ContentTypeFieldsExtractorInterface | |||
| * @return list<int> | ||||
| * | ||||
| * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException | ||||
| * @throws \Ibexa\AdminUi\Exception\FieldTypeExpressionParserException | ||||
| * @throws \LogicException | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This cannot be declared for the interface. It has to be a different type of exception, if needed.
Suggested change
|
||||
| */ | ||||
| public function extractFieldsFromExpression(string $expression): array; | ||||
|
|
||||
|
|
||||
Oops, something went wrong.
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.