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
Raphael at Digital Pianism
70.8k37 gold badges192 silver badges357 bronze badges
asked Apr 13, 2017 at 10:16

1 Answer 1

6

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();
}
answered Apr 13, 2017 at 10:24
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.