InstallScripts vs db_schema for new EAV attribute
سؤال
I'm in the process of adding new fields to my registration page. I know that we're now supposed to use db_schema instead of InstallScripts, but how can I make sure that they're seen as customer attributes, and editable with he rest of customer information?
Thanks
المحلول
db_schema.xml used only for table fields. It means that you can add only table field by db_schema, but not Magento EAV attribute.
To add new customer attribute you can use the following guide https://www.mageplaza.com/magento-2-module-development/magento-2-add-product-attribute-programmatically.html
But in attribute creating InstallData::install
method you should add 'used_in_forms'
property to attribute with content: 'used_in_forms' => ['adminhtml_customer', 'customer_account_create', 'customer_account_edit']
And if you are using Magento Enterprise edition, this attribute will be automatically shown on frontend otherwise you should display it manually.