/**
  * @param \Magento\Eav\Setup\EavSetup $eavSetup
  * @param array $attributes
  */
 public function installCustomerForms(EavSetup $eavSetup, array $attributes)
 {
     $customer = (int) $eavSetup->getEntityTypeId('customer');
     $customerAddress = (int) $eavSetup->getEntityTypeId('customer_address');
     /**
      * @var ModuleDataSetupInterface $setup
      */
     $setup = $eavSetup->getSetup();
     $attributeIds = [];
     $select = $setup->getConnection()->select()->from(['ea' => $setup->getTable('eav_attribute')], ['entity_type_id', 'attribute_code', 'attribute_id'])->where('ea.entity_type_id IN(?)', [$customer, $customerAddress]);
     foreach ($setup->getConnection()->fetchAll($select) as $row) {
         if (preg_match('/kana/', $row['attribute_code'])) {
             $attributeIds[$row['entity_type_id']][$row['attribute_code']] = $row['attribute_id'];
         }
     }
     $data = [];
     $usedInCustomerForms = ['customer_account_create', 'customer_account_edit', 'adminhtml_customer'];
     $usedInAddressForms = ['customer_register_address', 'customer_address_edit', 'adminhtml_customer_address'];
     $usedInForms = [];
     foreach ($attributeIds as $entity => $attrs) {
         foreach ($attrs as $attributeCode => $attributeId) {
             if ($entity == $customer) {
                 $usedInForms = $usedInCustomerForms;
             } else {
                 $usedInForms = $usedInAddressForms;
             }
             foreach ($usedInForms as $formCode) {
                 $data[] = ['form_code' => $formCode, 'attribute_id' => $attributeId];
             }
         }
     }
     if ($data) {
         $setup->getConnection()->insertMultiple($setup->getTable('customer_form_attribute'), $data);
     }
 }
 /**
  * Add customer attributes to customer forms
  *
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function installCustomerForms()
 {
     $customer = (int) parent::getEntityTypeId('customer');
     $customerAddress = (int) parent::getEntityTypeId('customer_address');
     $attributeIds = [];
     $select = $this->getSetup()->getConnection()->select()->from(['ea' => $this->getSetup()->getTable('eav_attribute')], ['entity_type_id', 'attribute_code', 'attribute_id'])->where('ea.entity_type_id IN(?)', [$customer, $customerAddress]);
     foreach ($this->getSetup()->getConnection()->fetchAll($select) as $row) {
         $attributeIds[$row['entity_type_id']][$row['attribute_code']] = $row['attribute_id'];
     }
     $data = [];
     $entities = $this->getDefaultEntities();
     $attributes = $entities['customer']['attributes'];
     foreach ($attributes as $attributeCode => $attribute) {
         $attributeId = $attributeIds[$customer][$attributeCode];
         $attribute['system'] = isset($attribute['system']) ? $attribute['system'] : true;
         $attribute['visible'] = isset($attribute['visible']) ? $attribute['visible'] : true;
         if ($attribute['system'] != true || $attribute['visible'] != false) {
             $usedInForms = ['customer_account_create', 'customer_account_edit', 'checkout_register'];
             if (!empty($attribute['adminhtml_only'])) {
                 $usedInForms = ['adminhtml_customer'];
             } else {
                 $usedInForms[] = 'adminhtml_customer';
             }
             if (!empty($attribute['admin_checkout'])) {
                 $usedInForms[] = 'adminhtml_checkout';
             }
             foreach ($usedInForms as $formCode) {
                 $data[] = ['form_code' => $formCode, 'attribute_id' => $attributeId];
             }
         }
     }
     $attributes = $entities['customer_address']['attributes'];
     foreach ($attributes as $attributeCode => $attribute) {
         $attributeId = $attributeIds[$customerAddress][$attributeCode];
         $attribute['system'] = isset($attribute['system']) ? $attribute['system'] : true;
         $attribute['visible'] = isset($attribute['visible']) ? $attribute['visible'] : true;
         if (false === ($attribute['system'] == true && $attribute['visible'] == false)) {
             $usedInForms = ['adminhtml_customer_address', 'customer_address_edit', 'customer_register_address'];
             foreach ($usedInForms as $formCode) {
                 $data[] = ['form_code' => $formCode, 'attribute_id' => $attributeId];
             }
         }
     }
     if ($data) {
         $this->getSetup()->getConnection()->insertMultiple($this->getSetup()->getTable('customer_form_attribute'), $data);
     }
 }