0

I am trying to inject all the values of a given path in the configuration as an array. I know I can inject Magento\Framework\App\Config\ScopeConfigInterface and get it from there using ScopeConfigInterface::getValue('my_path') but the problem is I am using a third party library that uses some config values and it expects an array to be injected.

I have worked it around by creating a new class that extends such a library and then call the parent constructor with the objects injected and also passing along an array I extract using ScopeConfigInterface::getValue('my_path'). However I would like to inject them directly to avoid unnecessary redundancy code. Any Ideas?

This can be summarized to how can I inject the value returned by a method in the di.xml.

1
  • Any ideas I still do not know how to do so? Commented Jan 6, 2016 at 0:09

1 Answer 1

0

Magento save country and states as array value (multi select input) , but stock in db like this (AT,BR,CA,CH,DE,EE,ES,FI,FR,LT,LV,RO,US) for reading the states use this function : const XML_PATH_STATES_REQUIRED = 'general/region/state_required';

public function getCountriesWithStatesRequired($asJson = false) { $value = trim( $this->scopeConfig->getValue( self::XML_PATH_STATES_REQUIRED, ScopeInterface::SCOPE_STORE ) ); $countryList = preg_split('/\,/', $value, 0, PREG_SPLIT_NO_EMPTY); if ($asJson) { return $this->jsonHelper->jsonEncode($countryList); } return $countryList; } 

i think this response will open some doors for you ..

1
  • Sorry this is not what I am looking for. I want to use di.xml to inject an array in a virtualtype. As of now, the only way I have figured out how to inject the adminhtml values is by using ScopeConfigInterface so I have done a workaround by injecting a ScopeConfigInterface interface into another class that extends the third party class and overwrite the constructor so it arranges my ScopeConfigInterface into an array and then call the parent constructor. I am hoping there is a better, way to do so. Commented Dec 31, 2015 at 12:33

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.