I added a custom attribute to my customer with a data patch script. The attribute is added in the database tables but when I try to register a new customer I get this error:
main.CRITICAL: Exception message: Missing required argument $options of Magento\Eav\Model\Entity\Attribute\Source\Config.
Did I do something wrong? and how to fix it?
This is my data patch script:
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace OSP\SubUsers\Setup\Patch\Data;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Customer\Setup\CustomerSetup;
/**
*/
class AddDebtorId implements DataPatchInterface, PatchRevertableInterface
{
/**
* @var \Magento\Framework\Setup\ModuleDataSetupInterface
*/
private $moduleDataSetup;
/**
* @var CustomerSetup
*/
private $customerSetupFactory;
/**
* @param \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup
* @param CustomerSetupFactory $customerSetupFactory
*/
public function __construct(
\Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup,
CustomerSetupFactory $customerSetupFactory
) {
/**
* If before, we pass $setup as argument in install/upgrade function, from now we start
* inject it with DI. If you want to use setup, you can inject it, with the same way as here
*/
$this->moduleDataSetup = $moduleDataSetup;
$this->customerSetupFactory = $customerSetupFactory;
}
/**
* {@inheritdoc}
*/
public function apply()
{
$this->moduleDataSetup->getConnection()->startSetup();
/** @var CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
$customerSetup->addAttribute( \Magento\Customer\Model\Customer::ENTITY, 'debtor_id', [
'type' => 'int',
'input' => 'select',
'label' => 'Debtor ID',
'backend' => '',
'source' => '',
'frontend' => '',
'required' => false,
'default' => 0,
'visible' => true,
'user_defined' => true,
'system' => false,
'is_visible_in_grid' => true,
'is_used_in_grid' => true,
'is_filterable_in_grid' => true,
'is_searchable_in_grid' => true,
'position' => 300
]);
$attribute = $customerSetup->getEavConfig()->getAttribute(\Magento\Customer\Model\Customer::ENTITY, 'debtor_id');
$attribute->addData(
[
'used_in_forms' => ['adminhtml_checkout','adminhtml_customer','customer_account_edit','customer_account_create']
]);
$attribute->save();
$this->moduleDataSetup->getConnection()->endSetup();
}
/**
* {@inheritdoc}
*/
public static function getDependencies()
{
return [
];
}
public function revert()
{
$this->moduleDataSetup->getConnection()->startSetup();
/** @var CustomerSetup $customerSetup */
$customerSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
$customerSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'debtor_id');
$this->moduleDataSetup->getConnection()->endSetup();
}
/**
* {@inheritdoc}
*/
public function getAliases()
{
/**
* This internal Magento method, that means that some patches with time can change their names,
* but changing name should not affect installation process, that's why if we will change name of the patch
* we will add alias here
*/
return [];
}
}