I'm making a plugin for the Magento\Framework\App\Config\ScopeConfigInterface file.
I need to get the config value from database.
Right now, I manage to accomplish this, but I'm having an issue with obscured fields.
I'm getting the value that comes directly from database.
If I inject the EncryptorInterface
I can decrypt
it, but the problem is that I need to know when is necessary to decrypt
and when should I need to return the value from database.
I have at this point of the flow the path for the config option (example: carriers/usps/userid )
I was looking for a way to detect the backend model for the field using the path to load the model.
I tried something like this:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$field = $objectManager->create('Magento\Config\Model\Config\Structure')->getElement($path);
And then try this to get the backend Model:
if ($field->hasBackendModel()) {
$backendModel = $field->getBackendModel();
//backend model is empty
}
Not sure how I can achieve to detect if the field has backend model Magento\Config\Model\Config\Backend\Encrypted
Is there some way to read the xml tree, and using the field path get the backend model, so I can know if I should use decrypt for returning the value or not?