Problem/Motivation
FileValidationConstraintValidator is a wrapper around the file_validate() function.
It currently assumes that it is being used to validate a \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem.
EntityReferenceItem::getTarget() can return either the typed data object representing the entity being referenced, or NULL if there is no entity.
All EntityReferenceItems also have a constraint of ValidReference which ensures that the entity exists.
If the entity (file) does not exist, the ValidReference validator will set the appropriate violation.
However, the FileValidation constraint will still run even when there is no file.
Proposed resolution
Respect the possible NULL return value of \Drupal\Core\TypedData\DataReferenceInterface::getTarget() before checking the file.
Do not append any additional violations if the file is not found, as the other constraint will handle it.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 2956814-file-4-PASS.patch | 2.29 KB | tim.plunkett |
| #4 | 2956814-file-4-FAIL.patch | 1.35 KB | tim.plunkett |
Comments
Comment #2
tim.plunkettWould help if I upload the patch.
Comment #3
borisson_It looks like there is no dedicated test for the
FileValidationConstraintValidator, this seems like the ideal time to add that test? If you disagree and this is out of scope for this issue, it does look very solid.Comment #4
tim.plunkettThere is a test class that claims to explicitly cover FileValidationConstraintValidator, but it is not named FileValidationConstraintValidatorTest.
Expanded that coverage.
Comment #6
andypostLooks great!
Comment #7
alexpottCrediting @borisson_ for asking for a test.
Committed and pushed 37b9e45ac0 to 8.6.x and d58b19b0ac to 8.5.x. Thanks!
Comment #11
viappidu commentedHas this been applied on 8.5.3 too?
Comment #12
koppie commented@viappidu I don't think so; this only made it into 8.5.7 & higher.
Comment #14
quietone commentedClosed #2900675: File validation fails when file does not exist. as a duplicate, adding credit.