moduleDataSetup = $moduleDataSetup; $this->customerSetupFactory = $customerSetupFactory; $this->attributeSetFactory = $attributeSetFactory; } /** * {@inheritdoc} */ public function apply() { $this->moduleDataSetup->getConnection()->startSetup(); /** @var CustomerSetup $customerSetup */ $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]); $customerEntity = $customerSetup->getEavConfig()->getEntityType(AttributeProvider::ENTITY); $attributeSetId = $customerEntity->getDefaultAttributeSetId(); $attributeSet = $this->attributeSetFactory->create(); $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); $customerSetup->addAttribute(AttributeProvider::ENTITY, 'district', [ 'type' => 'static', 'label' => 'District', 'input' => 'text', 'source' => '', 'required' => false, 'visible' => true, 'position' => 333, 'system' => false, 'user_defined' => false, 'backend' => 'Stemcell\ChineseDirectory\Model\Entity\Attribute\Backend\District' ]); $attribute = $customerSetup->getEavConfig()->getAttribute(AttributeProvider::ENTITY, 'district'); $attribute->addData([ 'used_in_forms' => [ 'adminhtml_customer_address', 'customer_address_edit', 'customer_register_address' ] ]); $attribute->addData([ 'attribute_set_id' => $attributeSetId, 'attribute_group_id' => $attributeGroupId ]); $attribute->save(); $this->moduleDataSetup->getConnection()->endSetup(); } public function revert() { $this->moduleDataSetup->getConnection()->startSetup(); /** @var CustomerSetup $customerSetup */ $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]); $customerSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'district'); $this->moduleDataSetup->getConnection()->endSetup(); } /** * {@inheritdoc} */ public function getAliases() { return []; } /** * {@inheritdoc} */ public static function getDependencies() { return [ ]; } }