Skip to content

IBX-9840: Implemented service fetching content fields from expression and validating if field is within expression #1500

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
wants to merge 5 commits into
base: 4.6
Choose a base branch
from

Conversation

barw4
Copy link
Contributor

@barw4 barw4 commented Mar 14, 2025

🎫 Issue IBX-9840

Description:

The parser will parse the following expressions:

expr         ::= (<group> '/')? <content_type> '/' <field> 
group        ::= id | '{' <id> (',' <id>)* '}'
content_type ::= id | '{' <id> (',' <id>)* '}' | '*'
field        ::= id | '{' <id> (',' <id>)* '}' 

and fetch asked field definitions, then provide an output in the form of a list that consists of field definition ids.

Example of usage:

$extractedFieldIds = $this->contentTypeFieldsExtractor->extractFieldsFromExpression('{Media,Content}/*/name');

will result in:

.array:2 [
  0 => 8
  1 => 9
]

There is also a possibility to check whether a FieldDefinition is within a given expression. The API reference is as follows:

ContentTypeFieldsByExpressionServiceInterface service:

interface ContentTypeFieldsByExpressionServiceInterface
{
    /**
     * @return list<\Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition>
     *
     * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
     */
    public function getFieldsFromExpression(string $expression): array;

    /**
     * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
     */
    public function isFieldIncludedInExpression(FieldDefinition $fieldDefinition, string $expression): bool;
}

For QA:

Documentation:

@barw4 barw4 added Feature New feature request Work in progress labels Mar 14, 2025
@barw4 barw4 self-assigned this Mar 14, 2025
Copy link

@barw4 barw4 changed the title IBX-9631: Implement parser fetching content fields from expression [WIP]IBX-9631: Implement parser fetching content fields from expression Mar 14, 2025
@barw4 barw4 changed the title [WIP]IBX-9631: Implement parser fetching content fields from expression IBX-9631: Implement parser fetching content fields from expression and validating if field is within expression Jul 30, 2025
@barw4 barw4 force-pushed the ibx-9631-taxonomy-suggestions-source-parser branch from 0da192d to 78947c5 Compare July 30, 2025 11:45
@barw4 barw4 marked this pull request as ready for review July 30, 2025 11:45
@barw4 barw4 requested a review from a team July 30, 2025 11:47
@ezrobot ezrobot requested review from adamwojs, mikadamczyk, Steveb-p, alongosz, ciastektk, ViniTou, wiewiurdp, konradoboza and tbialcz and removed request for a team July 30, 2025 11:48
@barw4 barw4 changed the title IBX-9631: Implement parser fetching content fields from expression and validating if field is within expression IBX-9840: Implement parser fetching content fields from expression and validating if field is within expression Jul 30, 2025
@barw4 barw4 changed the title IBX-9840: Implement parser fetching content fields from expression and validating if field is within expression IBX-9840: Implement service fetching content fields from expression and validating if field is within expression Jul 30, 2025
Copy link
Contributor

@mikadamczyk mikadamczyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to expose a method to validate an expression? Will it be possible to edit it by hand?

$this->expectSlash();
$fieldTokens = $this->parseSection();
} else {
throw new RuntimeException('Invalid expression, expected one or two T_SLASH delimiters.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about throwing a dedicated exception, like SyntaxError/Exception? And what about catching it, should it be in service or by client code? T_SLASH or "/" like here https://github.com/ibexa/admin-ui/pull/1500/files#diff-74127d24456a18e891c75260b495952ea2359a27853f3bea40933252aa41f3ffR133?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the Ibexa\AdminUi\Exception\FieldTypeExpressionParserException and imo it should be catched by client code to throw 4xx (when there is one)


$contentTypes = $this->resolveContentTypes($extractedMetadata);

return $this->mergeFieldIds($extractedMetadata[2], $contentTypes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of fetching by indexes, is it worth creating a structure for metadata?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean by that that public function parseExpression(string $expression): array should give us some kind of structured object instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, like ExpresionMetadata or sth

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please see a5bbca7

@barw4 barw4 force-pushed the ibx-9631-taxonomy-suggestions-source-parser branch from 7079418 to 0e1b4d7 Compare July 31, 2025 11:27
@barw4 barw4 requested a review from mikadamczyk July 31, 2025 11:31
@barw4 barw4 changed the title IBX-9840: Implement service fetching content fields from expression and validating if field is within expression IBX-9840: Implemented service fetching content fields from expression and validating if field is within expression Jul 31, 2025
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature request Ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants