-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[2.3] [Form] Renamed option "virtual" to "inherit_data" and improved handling of such forms #6573
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
Conversation
I think this PR should be split in 2:
What about considering |
@vicb Splitting this PR up in two would greatly increase my workload for no particular benefit. I don't like an |
I see Breaking BC ??? Which do you expect to be more frequent, extending the |
I expect neither of them to be very frequent. IMO the most useful purpose of So I think passing |
What I expect from a builder is to ease the construction of an object and I think |
Postponed to 2.3. |
As it's going to be merged in 2.3, the old behavior should be kept until 3.0. |
I've just re-read the documentation before and after the change. Frankly, I don't think that the new name is much better than the old one. Considering that this will break BC at some point, I would like that we reconsider this change. |
@bschussek two questions about this PR:
|
@bschussek will this PR fix #7570 ? |
Hi, I have created a code as below to create a form with little complicated layout. class Question{ protected $subject; protected $body; } class Answer{ protected $subject; protected $body; } class FormData{ protected $question; protected $answer; } class RowType extends AbstractType{ public function setDefaultOptions($resolver){ $resolver->setDefaults(array('virtual' => true)); } } class QuestionAndAnswerType extends AbstractType{ public function buildForm($builder, $options){ $builder->add('row1', 'row'); $builder->add('row2', 'row'); $row1 = $builder->get('row1'); $row2 = $builder->get('row2'); $row1->add('question_subject', 'text', array('property_path'=>'question.subject')); $row1->add('answer_subject', 'text', array('property_path'=>'answer.subject')); $row2->add('question_body', 'textarea', array('property_path'=>'question.body')); $row2->add('answer_body', 'textarea', array('property_path'=>'answer.body')); } } With the code above, I have created the form with layered structure as below. form row(virtual=true) text(property_path=question.subject) text(property_path=anwser.subject) row(virtual=true) textarea(property_path=question.body) textarea(property_path=anwser.body) This form will show the below as a content as well as results. <div class="row"> <div class="span6"> <input type="text"> </div> <div class="span6"> <input type="text"> </div> </div> <div class="row"> <div class="span6"> <textarea></textarea> </div> <div class="span6"> <textarea></textarea> </div> </div> However, this form returns an error as "Cannot write property "question_subject" to an array.". The code above is an example and It would be necessary to have a hypothetical FormType which does not affect property_path to create a complicated form. With that, I think the link below is a good sample and #6573 is a necessary function. Also, I would like to create a code as below which nested virtual formtype form row(virtual=true) cell(virtual=true) text(property_path=firstName) text(property_path=lastName) cell(virtual=true) textarea(property_path=comment) |
@shuogawa Did you test whether your form works with this PR applied? |
@fabpot I still think that "inherit_data" is much better than "virtual", especially when you contrast the two options used for data mapping:
|
Even if the new name is better, I'm not sure the difference is enough to justify a BC break. What others think? |
It is easy do |
@Koc: What about bundles or Open-Source that want to support several Symfony versions? |
|
@fabpot They can use the old name. "virtual" will remain in as an alias until 3.0. |
@aderuwe That's only part of the truth. The current naming (and documentation) suggested that virtual fields were somehow "skipped" by data mapping (which was the case). But truth is (after this PR) that they are not skipped. They just receive the same data as their parent. |
@bschussek but the use-case (structuring the form differently to the underlying model) will still work? I ask because I really understood them as "skipped" and have used them as such. I guess I'll need to modify some stuff here and there. :) That being said, |
@aderuwe You don't need to modify anything. The use cases of |
@bschussek Ok, then I think I need to change my opinion on the name change, |
Just to clarify again: Both |
@bschussek Can you update this PR to take into account that virtual will be supported until 3.0? |
Rebased and pushed. |
This PR was merged into the master branch. Discussion ---------- [2.3] [Form] Renamed option "virtual" to "inherit_data" and improved handling of such forms Bug fix: yes Feature addition: yes Backwards compatibility break: yes Symfony2 tests pass: yes Fixes the following tickets: #5899, #5720, #5578 Todo: - License of the code: MIT Documentation PR: symfony/symfony-docs#2107 This PR renames the option "virtual" to "inherit_data" for more clarity (the old option is deprecated and usable until 2.3). It also fixes the behavior of forms having that option set. Forms with that option set will now correctly return their parents' data from `getData()`, `getNormData()` and `getViewData()`. Furthermore, `getPropertyPath()` was fixed for forms that inherit their parent data. Commits ------- 1290b80 [Form] Fixed the deprecation notes for the "virtual" option ac2ca44 [Form] Moved parent data inheritance from data mappers to Form 8ea5e1a [Form] Renamed option "virtual" to "inherit_data"
So, just updated to 2.3 |
Bug fix: yes
Feature addition: yes
Backwards compatibility break: yes
Symfony2 tests pass: yes
Fixes the following tickets: #5899, #5720, #5578
Todo: -
License of the code: MIT
Documentation PR: symfony/symfony-docs#2107
This PR renames the option "virtual" to "inherit_data" for more clarity (the old option is deprecated and usable until 2.3). It also fixes the behavior of forms having that option set.
Forms with that option set will now correctly return their parents' data from
getData()
,getNormData()
andgetViewData()
. Furthermore,getPropertyPath()
was fixed for forms that inherit their parent data.