-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Add constraints_from_* options #50459
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
base: 7.4
Are you sure you want to change the base?
Conversation
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
Hey! Thanks for your PR. You are targeting branch "6.3" but it seems your PR description refers to branch "6.3 for features". Cheers! Carsonbot |
I think the target branch is 6.4 but she's behind the 6.3 so I didn't know which branch I must to target |
a16660d
to
017d72d
Compare
I don't understand why the high-deps and low-deps unit tests fail… Can anyone help me? |
6.4 is the right target, we merge 6.3 into 6.4 regularly so it will catch up eventually. |
017d72d
to
55cb5fe
Compare
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
@@ -7,6 +7,7 @@ CHANGELOG | |||
* Don't render seconds for HTML5 date pickers unless "with_seconds" is explicitly set | |||
* Add a `placeholder_attr` option to `ChoiceType` | |||
* Deprecate not configuring the "widget" option of date/time form types, it will default to "single_text" in v7 | |||
* Add `constraints_from_entity` and `constraints_from_property` option to `FormType` |
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.
for a new 6.4 section
Apply constraints to field from an entity not mapped by the form data_class. Fix fabbot review Fix changelog to 6.4
55cb5fe
to
fbe76e9
Compare
The job low-deps fails because it cannot find the trait |
Maybe the term "DTO" is not right, a form model will be more appropriate? An object who contains some properties to create some entities… Sometimes, you can have many forms… A form with When you make a form to create/edit an entity, it's recommanded to set constraints in this entity instead of each form field, isn't it? With the option Consider these entities (simplified):
You can easily imagine a form to create the first message which asks all theses entity (a category, a name and a message) (=a DTO with these properties) and another form to create the next messages which only asks a message (=TopicMessage Entity). // With a DTO (data_class => App\Form\Model\FirstTopicMessage::class)
$builder
->add('category', EntityType::class, [
'class' => TopicCategory::class
])
->add('name', TextType::class, [
'constraints_from_entity' => Topic::class
])
-> add('message', TextareaType::class, [
'constraints_from_entity' => TopicMessage::class
]) OR // With unmapped fields (data_class => App\Entity\TopicMessage::class)
$builder
->add('category', EntityType::class, [
'class' => TopicCategory::class,
'mapped' => false,
])
->add('name', TextType::class, [
'constraints_from_entity' => Topic::class,
'mapped' => false,
])
-> add('message', TextareaType::class) |
Apply constraints to field from an entity not mapped by the form data_class.
Use-cases:
Current usage:
You set constraints in your entities then create a DTO but you must duplicate your constraints in your DTO object to valide your fields.
New usage:
You set constraints in your entities then create a DTO and link your DTO form fields to your entities properties.
Usage:
Add
constraints_from_entity
option on any form field (child ofFormType::class
).If the entity related property name is different that the field name, you must provide
constraints_from_property
to declare the property name.Works on (un)mapped field and (un)set
data_class
form.Notes:
It's my first pull request, I hope I done all required things ;)