You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update: need to think about about this a bit more first - as a Form may require a Recaptcha field which isn't on the DataObject. It may make more sense to do something similar to #11402 where config on the DBField defines the FieldValidator's which can be used, likewise maybe it makes sense to add validators to DataObjects the same way instead of via getCMSCompositeValidator(). Other option is just call the validators in getCMSCompositeValidator() as part of DataObject::validate(), though this feels pretty inconsistent.
RequireFields is a commonly used form validator that is weirdly added via on DataObject::getCMSCompositeValidator(), despite DataObject not actually being a Form itself.
Form validation is not called as part of DataObject::write() / DataObject::validate(), meaning that the fields aren't actually required with programmatically updating the DataObject e.g. via an API call.
Instead we could enforce required fields by adding private static array $required = []; to DataObject where $db fields that are required are added. Those fields are then checked that they have values as part of DataObject::validate(), and if they are blank then ValidationResult::addFieldError($field, _t('KEY', 'Field is required')) is called.
$require should also enforce $has_one relations, though not any of the other relations, including belongs_to
Acceptance criteria
PRs targets CMS 5.4
DataObject fields are validated they are non-blank if they are defined in DataObject.required config
DataObject $has_one fields are validated they are non-zero
Validation messages show as appropriate in the CMS
RequiredFields is deprecated in CMS 5.4 and the message says to use DataObject.required instead
RequiredFields is removed from CMS 6
CMS 5 developer docs are updated to say use DataObject.required instead of RequireFields
The text was updated successfully, but these errors were encountered:
Update: need to think about about this a bit more first - as a Form may require a Recaptcha field which isn't on the DataObject. It may make more sense to do something similar to #11402 where config on the DBField defines the FieldValidator's which can be used, likewise maybe it makes sense to add validators to DataObjects the same way instead of via getCMSCompositeValidator(). Other option is just call the validators in getCMSCompositeValidator() as part of DataObject::validate(), though this feels pretty inconsistent.
RequireFields is a commonly used form validator that is weirdly added via on
DataObject::getCMSCompositeValidator()
, despite DataObject not actually being a Form itself.Form validation is not called as part of
DataObject::write() / DataObject::validate()
, meaning that the fields aren't actually required with programmatically updating the DataObject e.g. via an API call.Instead we could enforce required fields by adding
private static array $required = [];
to DataObject where $db fields that are required are added. Those fields are then checked that they have values as part ofDataObject::validate()
, and if they are blank thenValidationResult::addFieldError($field, _t('KEY', 'Field is required'))
is called.$require should also enforce $has_one relations, though not any of the other relations, including belongs_to
Acceptance criteria
The text was updated successfully, but these errors were encountered: