Question

I would like to create a custom config field and save it programatically using defined backend-model.

Context

Field is meant to be encrypted. Possibly validated via config Will be set via extended magento api method Config won't be accessible from admin panel

I've tried to utilize configWriter, but it doesn't consider backendModel:

<?php
namespace Company\Integration\Model;

use Magento\Framework\App\Config\Storage\WriterInterface;

class Setup {

    const API_KEY = 'paypal/wpp/api_signature';

    public function __construct(
        WriterInterface $configWriter
    ){
        $this->configWriter = $configWriter;
    }

    /**
     * {@inheritdoc}
     */
    public function setup($apiKey)
    {
        $this->configWriter->save(self::API_KEY, $apiKey);
    }
}

Result: The value is set in plain text, because it omits backend model logic

In above example, I'm saving paypal field, which is defined as encrypted. This is just a test scenario.

I was trying to trace back the way the config is saved via admin panel, but it seems too complex to reproduce.

Is there a proper way to do it, with accordance to backend model?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top