-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Ability to get entity constraints and message in FormBuilder class #16449
Comments
It's already possible to get this kind of information from the metadata factory: $metadata = $this->container->get('validator')
->getMetadataFactory()
->getMetadataFor('AppBundle\Entity\Post'); You could expose it as javascript, or decorate it in a view object and pass it to twig. Do we really need any additional support in core? |
I think we do because form should be able to gather all the constraints if data class is used. Furthermore, your code does not consider the following
Also I think code will be messy if same entity is used in different forms using different validation group since metadata retrieval process will have to be repeated. These are the few reasons to have this feature. Having said that I can understand that this feature may not be desired 100% of the time so there should be some mechanism to skip this if we want to. |
@nicholasnet I'm not saying you should write messy code and retrieve metadata directly from every form you create. You can abstract it away. I'm just saying it's possible. Since you've got a use case, perhaps you should try implementing this outside of a framework. It can always be integrated back later. It'd be easier to decide if you had something working. |
@jakzal I am sure it is possible right now but how can we go about achieving this using form class alone is a question. I know extracting metadata is not a problem but how about extracting formatted message and leveraging Symfony internationalization for those messages including constraints? I am more than happy to work on this feature I just need some guidance regarding how we can go about achieving this. It seems like issue somewhat like this was brought up before #11200 but it was turned down. But the feature that I am asking is bit different there is no json or js involved in this only PHP. |
@nicholasnet Thank you for your suggestion! As was said before, this is possible in userland already. If there's a very good implementation that we could simply add to the core, I'd consider it. But otherwise I don't think we will implement and support this ourselves. |
I think there should be a way to access all the entity constraints in Form class so that we can pass those information to client side without manually entering those constraints all over again in form class.
For example if we have code like this.
I would like to access these constraints with messages in form class so that we pass down these information to twig. Like this
Here data attribute should be customizable.
Currently this cannot be achieved without code duplication in either twig or in form class directly.
The text was updated successfully, but these errors were encountered: