Skip to content

Added a clientToApp method for use in the BindClientData event #3764

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

Closed
wants to merge 3 commits into from

Conversation

Burgov
Copy link
Contributor

@Burgov Burgov commented Apr 3, 2012

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes

This is an alternative to PR #3514. For an explanation as of why this method can be useful, please refer to the discussion there. In my opinion, this would be a very useful addition, but perhaps methods should be found to restrict it more, to prevent people from using it to get app data without actually binding the form.

@stof
Copy link
Member

stof commented Apr 3, 2012

this is wrong IMO as your transformation would not apply changes done by listeners (and so is incomplete). The issue with your approch in #3514 is that you are mixing the different representations of the data, as you expect your listener to use the app data whereas it works at the level of norm data or client data.

@Burgov
Copy link
Contributor Author

Burgov commented Apr 3, 2012

Hmm... You're right about the listeners. I added them to the method.

I'm still convinced that in some (many) cases the app data (of children) is necessary in the bind_client_data event. Two examples are shown in the beforementioned PR.

In the previous PR you stated that I was probably using the wrong event, yet BindClientData is the only event to use. For example, I have a form with a country field and a state field. Someone changes the country from Netherlands (no states) to USA (has states). The state field is actually added and the user submits some data. Then the form gets submitted and bound a second time. Since the original data still had the country NL, a state field is only added from the listener. If I'd do this in the BindNormData event, I'd have the correct Country entity available together with its getStates() method, but since a state field was not yet created, the client data can and will never be mapped and therefor gets lost. If I'd do it in the BindClientData event, all I'd have is a country ID and no way to fetch its states, so I'm not able to generate the state field with its correct choice list.

As stated before, I'd either have to fetch the country from the EM which I'd also have to inject into the form to be able to inject it into the listener, or use the forms Transformers, which already have the necessary services injected...

@Burgov
Copy link
Contributor Author

Burgov commented Apr 3, 2012

Come to think of it, now it's still not correct, of course, as there is a lot of logic missing between clientToNorm and normToApp...

@Burgov
Copy link
Contributor Author

Burgov commented Apr 3, 2012

I did some updates. Perhaps this is better? Although some checks need to be made to check whether the key is set in the clientData array

@webmozart
Copy link
Contributor

Data transformation and fired events should only occur during binding and prepopulation (setData). We need a new mechanism here that works in scope of the bind() method. I created a new issue (linked above) that summarizes the essence of this PR in a feature request.

@webmozart webmozart closed this Apr 3, 2012
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