How can I add customer attribute in Magento 2?
Note: This answer was referring to magento2-dev-beta and the code for setup scripts is not the same anymore in Magento 2.x.
Finally I can provide answer to my question. Adding customer attribute and having it displayed in backend form doesn't require to change anything in XML files. It could be achieved by doing following in install/upgrade script:
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
$customerSetup->addAttribute(
\Magento\Customer\Model\Customer::ENTITY,
'nickname',
[
'label' => 'Nickname',
'required' => 0,
'system' => 0,
'position' => 100
]
);
$customerSetup->getEavConfig()->getAttribute('customer', 'nickname')
->setData('used_in_forms', ['adminhtml_customer'])
->save();
system
property set to 0 is crucial, in other case attribute value won't be saved.
It works well on current develop branch.