-
-
Notifications
You must be signed in to change notification settings - Fork 51
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 callable field #321
Add callable field #321
Conversation
228c8fe
to
6a1c438
Compare
docs/field_types.md
Outdated
By default it uses the name of the field, but you can specify the path | ||
alternatively. For example: | ||
|
||
<details open><summary>PHP</summary> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reworked the feature and introduced a new way to define callbacks, inspired by Loic's comment:
sylius_grid:
grids:
app_user:
fields:
name:
type: callback
options:
callback: "callback:strtoupper"
label: app.ui.name
This approach allows string callables to be defined directly in YAML.
When configuring grids using PHP, both string and array callables are supported.
When configuring grids using service definitions, everything is supported: string callables, array callables, and closures.
I’ve documented this change here: SyliusGridBundle PR #321.
To implement this, I copied the OptionParser
class from the ResourceBundle, slimming it down to only what’s necessary for this feature (handling callbacks). See the original class: OptionsParser in ResourceBundle.
Since the resource bundle is not a required dependencie, I think this is fine to copy the class. However having two OptionParser
might not be ideal. Please let me know what you think about it.
6a1c438
to
ed2cd03
Compare
ed2cd03
to
47d1dd0
Compare
47d1dd0
to
c31e0cd
Compare
11c567d
to
bf89482
Compare
|
bf89482
to
f8f212f
Compare
9b34561
to
716d932
Compare
716d932
to
84925de
Compare
9a17200
to
bfe9951
Compare
02c7ff4
to
58f0dbc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Florian-Merle! 🎉 |
The documentation associated for this PR can be found here Sylius/Stack#228