I try to validate some fields before saving the entry, if the field is invalid, prevent the entry from saving and return the error message, I'm doing it via Element::EVENT_BEFORE_SAVE event.
It works for such a Plain Text field
// the attribute 'resourceTitle' is the field's handle
$entry->addError('resourceTitle', 'The title is invalid.');
But for a Matrix field, I don't what's the attribute, using the field handle(resourceId) is not working.
the source code the field is something like this:
<input type="text" id="fields-products-blocks-167910-fields-resourceId" name="fields[products][blocks][167910][fields][resourceId]" value="796">
I tried:
$entry->addError('resourceId', 'The resource id is invalid');
$entry->addError('fields-products-blocks-167910-fields-resourceId', 'The resource id is invalid');
$entry->addError('fields[products][blocks][167910][fields][resourceId]', 'The resource id is invalid');