Problem/motivation
Currently, reusing validator objects statically cached with Drupal/Core/Validation/ConstraintValidatorFactory leads to incorrect outcome when recursively validating entities, which is described in #3096811: Reusing initialized constraint validators overwrittes validation errors . The solution proposed there is to avoid re-using validator instances, which makes class ConstraintValidatorFactory useless.
Proposed resolution
- Temporary switch the context on the validator by preserving the previous one.
This is a better approach, but not feasible at the moent as the base class and interface for constraint validators are provided by Symfony and they lack the ability to retrieve the context. - Remove ConstraintValidatorFactory and call class resolver directly.
If we want to switch to 1) at some point we need to convince Symfony to add the context getter method for us in the constraint validators.
Comments
Comment #2
hchonov