卸载插件时删除默认配置

问题描述 投票:0回答:2

我有一个插件,我在安装时设置配置默认值 - config.xml 中的“defaultValue”选项无法开箱即用:

    private function addDefaultConfiguration(): void
    {
        $this->setValue('hoverstyle', array('tile-border'));


    }

如何通过卸载方法删除它?

在开发者页面找不到任何提示

default-value shopware6
2个回答
0
投票

您应该能够在

uninstall
插件生命周期方法中执行此操作。

SystemConfigService
有一个
delete
方法,您可以使用它删除单个条目,甚至还有
deletePluginConfiguration
方法,它应该删除插件的任何条目。

public function uninstall(UninstallContext $context): void
{
    parent::uninstall($context);

    if ($context->keepUserData()) {
        return;
    }

    $systemConfigService = $this->container->get(SystemConfigService::class);
    $systemConfigService->delete($this->getName() . '.hoverstyle');
}

这样的事情应该可以解决问题。请记住,仅当

$context->keepUserData()
为 false 时才删除插件数据。


© www.soinside.com 2019 - 2024. All rights reserved.