1

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. [] []

Manashvi Birla
8,8739 gold badges29 silver badges53 bronze badges
asked May 3, 2016 at 13:43

1 Answer 1

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);
}
answered May 3, 2016 at 13:47
7
  • I gives me the same error [2016年05月03日 14:36:30] main.CRITICAL: Missing required argument $text of Magento\Framework\Phrase. [] [] Commented May 3, 2016 at 14:35
  • @GianniDiFalco did you flush the var folders ? Also try to add a try/catch statement around the code in the beforeSave method Commented May 3, 2016 at 14:36
  • Do i have to delete all var/* folder? Or just my var/generation/myvendor/moydmoule? Commented May 3, 2016 at 14:42
  • @GianniDiFalco var/generation, var/cache, var/view_preprocessed Commented 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 page Commented May 3, 2016 at 14:56

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.