I successfully add customer custom attribute for magento 2.2.5 like this:
$setup->startSetup();
$insertArray = array(
'profile_picture' => array("type" => "varchar", "label" => "Profile Picture"),
'security_question_1' => array("type" => "int", "label" => "Security Question 1"),
'security_question_2' => array("type" => "int", "label" => "Security Question 2"),
'security_answer_1' => array("type" => "varchar", "label" => "Security Answer 1"),
'security_answer_2' => array("type" => "varchar", "label" => "Security Answer 2")
);
foreach ($insertArray as $key => $data) {
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
$customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
$attributeSetId = $customerEntity->getDefaultAttributeSetId();
/** @var $attributeSet AttributeSet */
$attributeSet = $this->attributeSetFactory->create();
$attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);
$customerSetup->addAttribute(Customer::ENTITY, $key, [
'type' => $data['type'],
'label' => $data['label'],
'input' => 'text',
'required' => false,
'visible' => true,
'user_defined' => true,
'sort_order' => 1000,
'position' => 1000,
'system' => 0,
]);
$attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, $key)
->addData([
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
'used_in_forms' => ['adminhtml_customer'],
]);
$attribute->save();
}
$setup->endSetup();
I can retrieve and set the value programmatically, but the problem is when i edit customer in backend and go to account information tab, it doesn't load the input field for my custom attribute? if there is something missing, how can i update the customer custom attribute?