2

I am getting this error after compiling in command prompt,

Incorrect dependency in class ParadoxLabs\TokenBase\Helper\Data in

/var/www/html/magento2/app/code/ParadoxLabs/TokenBase/Helper/Data.php

\Psr\Log\LoggerInterface already exists in context object

\Magento\Framework\App\Config\ScopeConfigInterface already exists in context object

I have added scope config dependency in my helper.

But as it says, that it is already present in context, then how to use it to fetch config values.

Currently I am using this way to get config values

$this->_scopeConfig->getValue('section/group/field');

Now how to access same, by using context object

Injection for my context object is

\Magento\Framework\App\Helper\Context $context
5

If your helper extends Magento\Framework\App\Helper\AbstractHelper then you don't need to add the ScopeConfigInterface dependency again in your constructor because the parent class already has that dependency.

You can simply do:

$this->scopeConfig->getValue('section/group/field');

Please note that the parent class variable does not start with an underscore.

Same remark for the Context dependency, you do not need to re add it as it's already part of the parent constructor.

FYI, the AbstractHelper constructor looks like this:

public function __construct(Context $context)
{
    $this->_moduleManager = $context->getModuleManager();
    $this->_logger = $context->getLogger();
    $this->_request = $context->getRequest();
    $this->_urlBuilder = $context->getUrlBuilder();
    $this->_httpHeader = $context->getHttpHeader();
    $this->_eventManager = $context->getEventManager();
    $this->_remoteAddress = $context->getRemoteAddress();
    $this->_cacheConfig = $context->getCacheConfig();
    $this->urlEncoder = $context->getUrlEncoder();
    $this->urlDecoder = $context->getUrlDecoder();
    $this->scopeConfig = $context->getScopeConfig();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.