Magento2:如何在使用Setup/uninstall.php(removeAttribute)卸载模块时删除创建的eav属性
我创建了一个模块JuistdIT_CustomAttributeCustomer,将自定义eav属性添加到客户实体中。我使用addAttribute将该功能添加到Setup/InstallData.php文件中Magento2:如何在使用Setup/uninstall.php(removeAttribute)卸载模块时删除创建的eav属性,php,magento2,Php,Magento2,我创建了一个模块JuistdIT_CustomAttributeCustomer,将自定义eav属性添加到客户实体中。我使用addAttribute将该功能添加到Setup/InstallData.php文件中 $customerSetup->addAttribute(Customer::ENTITY, 'test_2', [ 'type' => 'varchar', 'label' => 'Test 2', 'input'
$customerSetup->addAttribute(Customer::ENTITY, 'test_2', [
'type' => 'varchar',
'label' => 'Test 2',
'input' => 'text',
'required' => false,
'visible' => true,
'user_defined' => true,
'sort_order' => 1000,
'position' => 1000,
'system' => 0,
//"backend" => "",
//"source" => "",
"default" => "",
//"frontend" => "",
//"unique" => false,
//"note" => ""
'is_used_in_grid' => true,
'is_visible_in_grid' => true,
'is_filterable_in_grid' => true,
'is_searchable_in_grid' => true,
]);
但是,当我卸载模块时:
php bin/magento module:uninstall JuistdIT_CustomAttributeCustomer
我希望卸载模块时删除所有添加的EAV属性。因此,我添加了一个Setup/uninstal.php脚本,我想在其中使用removeAttribute函数:
$customerSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, "test_2");
但ModuleDataSetupInterface在卸载中不可用,因此我无法使用:
public function uninstall(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
/** @var CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
$customerSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, "test_2");
有人能帮我在“class uninstall implements UninstallInterface”的卸载函数中使用removeAttribute函数吗
谢谢我也在想,你找到答案了吗?