Skip to content

[Form] Add prototype_options to CollectionType #45605

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 1 commit into from
Apr 3, 2022

Conversation

michaelKaefer
Copy link
Contributor

@michaelKaefer michaelKaefer commented Mar 1, 2022

Q A
Branch? 6.1
Bug fix? no
New feature? yes
Deprecations? no
Tickets -
License MIT
Doc PR symfony/symfony-docs#16664

Allows defining options for the form for new entries (the prototype form) which differ from the options for the form for existing entries.

My use case: I need this when using EasyAdminBundle. In the form for an entity Person I have a CollectionType for a related entity Books. There I can edit the Books that a Person already has and add new Books. The change would allow me to show (or disable, etc.) a form field in the Book form only when an existing Book is edited (and not show it when a new Book is added).

As far as I can tell it is not a BC break to add this new option. I can provide another PR for the docs if this should get merged.

@carsonbot
Copy link

Hey!

I think @HeahDude has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@michaelKaefer
Copy link
Contributor Author

Hello @xabbuh, do you think there is any chance that this gets merged? I would like to close it if there is no chance. Thanks for any answer.

@xabbuh
Copy link
Member

xabbuh commented Mar 18, 2022

@michaelKaefer This sounds reasonable to me.

@michaelKaefer
Copy link
Contributor Author

michaelKaefer commented Mar 18, 2022

@xabbuh Do you mean the PR sounds reasonable or closing the PR sounds reasonable?

Copy link
Member

@yceruto yceruto left a comment

Choose a reason for hiding this comment

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

Looks good to me, after a minor comment

michaelKaefer added a commit to michaelKaefer/symfony-docs that referenced this pull request Mar 28, 2022
@michaelKaefer
Copy link
Contributor Author

@xabbuh @yceruto Thank you, I added the allowed type definition and created a PR for the docs: symfony/symfony-docs#16664.

@nicolas-grekas
Copy link
Member

Can you please add a test case, and also a line in the changelog of the component?

@michaelKaefer
Copy link
Contributor Author

@nicolas-grekas Sorry, I forgot that, I added both now.

@nicolas-grekas
Copy link
Member

Thank you @michaelKaefer.

@nicolas-grekas nicolas-grekas merged commit b881a7e into symfony:6.1 Apr 3, 2022
@michaelKaefer michaelKaefer deleted the patch-1 branch April 3, 2022 09:05
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Apr 4, 2022
This PR was submitted for the 6.0 branch but it was merged into the 6.1 branch instead.

Discussion
----------

[Form] Add new prototype_options

Related PR: symfony/symfony#45605

Commits
-------

ec76b6a [Form] Add new prototype_options
@fabpot fabpot mentioned this pull request Apr 15, 2022
javiereguiluz added a commit to EasyCorp/EasyAdminBundle that referenced this pull request Jun 4, 2022
This PR was merged into the 4.x branch.

Discussion
----------

Use CRUD form in CollectionField

Implements what `@furang` wrote here: #4766.

Needs Symfony 6.1 because it uses `prototype_options` (See symfony/symfony#45605).

I createad a reproducer here: https://github.com/michaelKaefer/ea-reproducer/tree/issue/4766-create-update-relations.

Without this PR you have to create a form type and set it as entry type for associated entities when using `CollectionField`. This doesn't allow using EA fields and could sometimes kind of duplicates the CRUD form of the associated entity. This new option would enable you to use the CRUD form (if you need different form fields and you cannot reuse the CRUD form you still can implement a custom form type).

Related to #3304.

Commits
-------

24a99a1 Use CRUD form in CollectionField
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants