Skip to content

Admin Config

Code Slicer edited this page Sep 15, 2022 · 4 revisions

Handles core_config_data (admin config related fields) changes. Import it as follows:

private Migration\Facade\AdminConfig $adminConfig;

public function __construct(
    Migration\Context $context,
    Migration\Facade\AdminConfig $adminConfig
) {
    parent::__construct($context);
    $this->adminConfig = $adminConfig;
}

get($path, $scope = ScopeConfig::SCOPE_TYPE_DEFAULT, $scopeId = null)

Retrieve existing config for given path:

$username = $this->adminConfig->get('my/module/user');

set($path, $value = null, $scope = ScopeConfig::SCOPE_TYPE_DEFAULT, $scopeId = 0)

Overrides existing entry, or create a new one if needed.

$this->adminConfig->set('payment/creditcard/identifier', 'My Store');

restore($path, $scope = ScopeConfig::SCOPE_TYPE_DEFAULT, $scopeId = 0)

Equivalent to checking the "restore" checkbox on admin. Force the setting to fallback to its default (defined on some config.xml):

$this->adminConfig->reset('shipping/carrier/show_foo_in_checkout');

append($path, $value, $scope = ScopeConfig::SCOPE_TYPE_DEFAULT, $scopeId = null)

That's an odd one. It allows appending a value to a given setting. Useful for managing the html scripts theme field and similar ones.

$this->adminConfig->append('design/head/includes', <<<HTML
    <script src="https://another.slow.chat/script.js" async></script>
HTML);