Problem/Motivation
\Drupal\Core\Theme\Component\ComponentValidator
has a method to setValidator
This allows contrib modules to change how the component validator behaves, including things like
- Add their own constraints (JSON Schema constraints, not Symfony validation constraints! So:
\JsonSchema\Constraints\ConstraintInterface
implementations, not\Symfony\Component\Validator\Constraint
subclasses) - Changing the constraint factory (again: JSON Schema constraints!)
These however are ignored by ::validateProps
as it calls $validator = new Validator()
instead of using the set validator
Steps to reproduce
Try to override the constraint factory by doing something like this:
$component_validator = new ComponentValidator();
$component_validator->setValidator(new Validator((new Factory())->setConstraintClass('format', UrlHelperFormatConstraint::class)));
where UrlHelperFormatConstraint
is a custom constraint.
Proposed resolution
Use the existing validator after resetting it