Skip to content
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

add callback field #321

Open
wants to merge 2 commits into
base: 1.13
Choose a base branch
from
Open

Conversation

Florian-Merle
Copy link
Contributor

@Florian-Merle Florian-Merle commented Mar 22, 2024

The Callback column aims to offer almost as much flexibility as the Twig column, but without requiring the creation of a template.
You simply need to specify a callback, which allows you to transform the 'data' variable on the fly.

docs/field_types.md Outdated Show resolved Hide resolved
docs/field_types.md Outdated Show resolved Hide resolved
@Florian-Merle Florian-Merle force-pushed the callback-field branch 4 times, most recently from 228c8fe to 6a1c438 Compare March 22, 2024 15:48
src/Bundle/Resources/config/services/field_types.xml Outdated Show resolved Hide resolved
src/Component/FieldTypes/CallbackFieldType.php Outdated Show resolved Hide resolved
src/Component/FieldTypes/CallbackFieldType.php Outdated Show resolved Hide resolved
src/Component/FieldTypes/CallbackFieldType.php Outdated Show resolved Hide resolved
src/Component/spec/FieldTypes/CallbackFieldTypeSpec.php Outdated Show resolved Hide resolved
By default it uses the name of the field, but you can specify the path
alternatively. For example:

<details open><summary>PHP</summary>
Copy link
Member

Choose a reason for hiding this comment

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

To match existing documentation, please add YAML example as well.

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 did not include documentation for the YAML format because I believe it's impossible to define a callback field in this format.

Copy link
Member

Choose a reason for hiding this comment

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

Feature is not complete then and cannot be merged until YAML support will be dropped.

Here is example on how callback can be implemented with non-php config format.

https://symfony.com/doc/current/reference/constraints/Callback.html#external-callbacks-and-closures

Copy link
Member

Choose a reason for hiding this comment

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

I think we can do it. The repository can be a callback in YAML.

app_book_by_english_authors:
    driver:
        name: doctrine/orm
        options:
            class: App\Entity\Book
            repository:
                method: [expr:service('app.english_books_query_builder'), create]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants