ComponentValidator ignores the set validator and creates a new one

Created on 31 March 2025, 3 days ago

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
  • Changing the constraint factory

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

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.0 🔥

Component

single-directory components

Created by

🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

Live updates comments and jobs are added and updated live.
  • Contributed project blocker

    It denotes an issue that prevents porting of a contributed project to the stable version of Drupal due to missing APIs, regressions, and so on.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024