Feature #77450
closedEasier Validation handling inside initilize*Actions
0%
Description
Half day is gone and i couldn't find any good solution for my problem without writing my own validator or ended up with a second model.
First i want to describe my problem here. This are my models:
My order has to address properties, one for shipping (mandatory) and one for the billing (optional). The address model has some mandatory fields. There is a checkbox to show the billing address. Everthing works out of the box if
the user need both addresses. But in the case the shipping address and the billing address are the same, he only has to fill out the first address fields.
I know i could write my own validator, but than i have to check all my address properties by my self, and i thought about a solution to turn off the validtor for the property billlingAddress when the checkbox is not set. And i think the best
place for the would be the initilize*Actions
There should be an easy way to do that, similar to the propertyMappingConfiguration.
Pseudocode inside an initilize*Action:
if ($this->arguments->hasArgument('order') && $showBillingAddress === TRUE) { $orderValidator = $this->arguments->getArgument('order')->getValidator(); $orderValidator->forProperty('billingAddress')->removeValidator() // or $orderValidator->skipValidationForProperty('billingAddress') }
By the way, this would give us a more dynamic way for validation for specific actions, without the need to write a own model validator for smaller problems like this. Or did I overlooked anything?
Files