Skip to content

FieldErrorDecorator

Marks a field that failed validation, by putting the configured error class on it and on whatever else the error class map points at.

The field itself is not always what should be styled: a designer may want the class on a wrapping div, or on the label rather than the input. So the map is XPath keyed — each expression is evaluated from the field (and from each of its labels) and the class lands on whatever it selects. The first expression that selects anything wins, which is what makes the map an ordered list of increasingly general fallbacks rather than a set of independent rules.

Labels are collected two ways because HTML allows both: a label wrapping the input, and one elsewhere pointing at it by for.

final readonly class FieldErrorDecorator

SourceUtil/FormPopulation/FieldErrorDecorator.php

public function __construct(\Closure(string, ?\DOMElement): array<int, \DOMElement> $queryElements, string $xmlnsPrefix): mixed

ParameterTypeDescription
$queryElements\Closure(string, ?\DOMElement): array<int, \DOMElement>
$xmlnsPrefixstring

Returns mixed

MethodDescription
decorate(DOMElement $element, DOMElement $form, array<string, mixed> $errorClassMap): void

public function decorate(DOMElement $element, DOMElement $form, array<string, mixed> $errorClassMap): void

XPath expression => class name.

ParameterTypeDescription
$elementDOMElement
$formDOMElement
$errorClassMaparray``<``string``, ``mixed``>XPath expression => class name.