I had setup this system.xml file
...
<section id="account_info" translate="label" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Account configuration</label>
<tab>account_info_tab</tab>
<resource>myvendor_mymodule::config</resource>
<group id="account_configuration" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Account login</label>
<field id="title" translate="label comment" type="text" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Token API</label>
<backend_model>Myvendor\Mymodule\Model\Config\TokenAPI</backend_model>
<validate>required-entry</validate>
</field>
</group>
</section>
...
I want to use a custom backend_model because i want to verify the data before saving it (have to use web services).
Then i have my TokenAPI backend_model
class TokenAPI extends \Magento\Framework\App\Config\Value{
function __construct(\Magento\Framework\Exception\LocalizedException $e){
$this->localizedException = $e;
}
public function beforeSave(){
echo '<pre>';
print_r($this->getValue());
echo '</pre>';
exit;
}
}
The problem that im having is that as soon i uncomment the backend_model in system.xml the field stops working throwing this error
[2016年05月03日 13:28:23] main.CRITICAL: Missing required argument $text of Magento\Framework\Phrase. [] []
1 Answer 1
The problem is that your backend model constructor does not match the parent class constructor \Magento\Framework\App\Config\Value
You need to update your constructor like this:
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\App\Config\ScopeConfigInterface $config,
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
\Magento\Framework\Exception\LocalizedException $e,
array $data = []
) {
$this->localizedException = $e;
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
}
-
I gives me the same error [2016年05月03日 14:36:30] main.CRITICAL: Missing required argument $text of Magento\Framework\Phrase. [] []Gianni Di Falco– Gianni Di Falco2016年05月03日 14:35:24 +00:00Commented May 3, 2016 at 14:35
-
@GianniDiFalco did you flush the
varfolders ? Also try to add atry/catchstatement around the code in thebeforeSavemethodRaphael at Digital Pianism– Raphael at Digital Pianism2016年05月03日 14:36:27 +00:00Commented May 3, 2016 at 14:36 -
Do i have to delete all var/* folder? Or just my var/generation/myvendor/moydmoule?Gianni Di Falco– Gianni Di Falco2016年05月03日 14:42:56 +00:00Commented May 3, 2016 at 14:42
-
@GianniDiFalco
var/generation,var/cache,var/view_preprocessedRaphael at Digital Pianism– Raphael at Digital Pianism2016年05月03日 14:44:30 +00:00Commented May 3, 2016 at 14:44 -
Same error, the try/catch does not even execute even if a save the config with no fields showing up. The error shows in system.log and when loading the pageGianni Di Falco– Gianni Di Falco2016年05月03日 14:56:36 +00:00Commented May 3, 2016 at 14:56
Explore related questions
See similar questions with these tags.