Element Validator Service¶
Service identity¶
- Service ID:
name.element_validator - Interface:
Drupal\name\Service\ElementValidatorInterface - Class:
Drupal\name\Service\ElementValidatorService - Visibility:
@internal— validation runs through thenameform element; custom modules should use#type => 'name'and field widgets.
Validates minimum components, required state, and partial input on the Name
form element. Works with Drupal\name\Utility\NameComponents for empty checks
and missing-component detection.
Primary method¶
validate(array $element, FormStateInterface $form_state): array¶
Called from Name::validate(). When #needs_validation is set:
- Enforces
#minimum_componentsagainst filled values. - Applies
#allow_family_or_givenlogic when configured. - Sets form errors on the element or individual components depending on whether
inline_form_errorsis enabled.
Returns the element array (possibly with #errors or child errors attached).
Related services¶
name.component_metadata— translated component labels used in error messages (NameComponentMetadataService).