php - FormHelper::getSourceValue() doesn't return entity on validation errors in CakePHP4

one text

Solution:

The form helper will by default use the values from the request data in case present, so that your form is populated with the data entered by the user after it has been submitted, otherwise the data entered by the user could be lost, for example on validation errors, in which case the invalid data is not being set on the entity.

If you want to use data unrelated to what you're submitting, then you're usually best of to obtain it directly from the entity that you're using for the form instead, or, depending on the situation, from a separately queried entity, one that is never being touched by neither the form helper, nor the patching mechanism in the controller.

Long story short, use $article->photos instead of $this->Form->getSourceValue('photos').

Source