Skip to content
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

[Form] Document data mappers #5459

Closed
wouterj opened this issue Jun 28, 2015 · 3 comments
Closed

[Form] Document data mappers #5459

wouterj opened this issue Jun 28, 2015 · 3 comments
Labels
actionable Clear and specific issues ready for anyone to take them. DX Form hasPR A Pull Request has already been submitted for this issue.

Comments

@wouterj
Copy link
Member

wouterj commented Jun 28, 2015

Data mappers are really great things and they are mentioned zero times in the documentation. We really have to fix it (especially in this era of value objects).

An example of a data mapper: https://gist.github.com/webmozart/36b1cd8a68a5f7844268
A presentation about it: https://youtu.be/Q80b9XeLUEA?t=20m18s

@wouterj wouterj added Missing Documentation actionable Clear and specific issues ready for anyone to take them. Form DX labels Jun 28, 2015
@weaverryan
Copy link
Member

I had no idea this existed. In fact, I think this solves a problem that I recently told someone was impossible :)

@xabbuh
Copy link
Member

xabbuh commented Sep 9, 2015

FYI, @webmozart just published a blog post giving more details about this: https://webmozart.io/blog/2015/09/09/value-objects-in-symfony-forms/

@stof
Copy link
Member

stof commented Sep 27, 2015

Be careful about this though. There is a point missing in the blog post of @webmozart: data mapping runs before the validator (as the validator runs on your model). This means that this approach does not work if your value object throws exceptions when trying to instantiate it in a wrong state (which is a best practice). your user would receive a 500 error (because of the exception) instead of seeing nice validation errors on the form.

@javiereguiluz javiereguiluz added the hasPR A Pull Request has already been submitted for this issue. label Sep 1, 2016
@xabbuh xabbuh closed this as completed Dec 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actionable Clear and specific issues ready for anyone to take them. DX Form hasPR A Pull Request has already been submitted for this issue.
Projects
None yet
Development

No branches or pull requests

5 participants