Problem
At #2429037: Allow adding entity level constraints we figured entity references do not validate auto-created entities for being valid. If there is custom validation logic e.g. on their label this should be run though?
By allowing for validating new entities a bug in the recursive validation was discovered, which didn't allow for the validation errors of the referenced entities to propagate. The problem is that if a constraint validator triggers the validation of a referenced entity and that referenced entity has the same constraint then currently we'll reuse the same instance of the validator and exchange its execution context while validating the referenced entities. This will lead to loosing the validation errors of the referenced entities.
Proposed resolution
- Let the current ValidReferenceConstraint also validate new entities.
- Remove the static cache for initialized constraint validator instances.
Remaining tasks
None.
User interface changes
Validation errors of newly created referenced entities will be shown.
API changes
New methods:
FieldableEntityInterface::isValidationRunning()
FieldableEntityInterface::isValidated()
FieldableEntityInterface::setValidated()
FieldableEntityInterface::validate()
now states that whoever is validating an entity is also responsible for showing its validation errors, otherwise other validation logic might decide to skip the validation of the entity based on the output of FieldableEntityInterface::isValidated()
, which could be disabled by calling FieldableEntityInterface::setValidated(FALSE)
on the validated entity in order to allow other further code to validate the entity. The purpose of this is to prevent showing the same errors multiple times.