I have added a custom customer attribute.
I need to enable backend validation for this field in registration form, edit customer form, etc. It needs to be required and unique field. Or not, depending on choices made in admin. I thought of a few possible solutions but they seem difficult to pull off and I am new to Magento development. What approach would you recommend to doing this?
I was thinking I could try and edit attribute options is_required and is_unique in afterSave() of the system.xml BackendModel. This option is not easy as it seems, since doing it outside Setup can cause problems. ( Magento2 - programmatically add product attribute options )
Perhaps another option might be adding some backend validation in a plugin that would execute before the data in the registration and edit forms is saved, but this would take a lot of plugins I suppose.
Help? How would you approach this task?