0

I have created a module with custom system config entries :

Vendor/Module/etc/adminhtml/system.xml

<?xml version="1.0"?>
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
     <system>
         <tab id="mainconfig" translate="label" sortOrder="1">
             <label>Mine Special</label>
         </tab>
         <section id="fooconfig" translate="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
             <class>separator-top</class>
             <label>FOO Configuration</label>
             <tab>mainconfig</tab>
             <resource>Vendor_Module::fooconfig_configuration</resource>

            <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>Emails Configuration</label>
                <field id="foo_mail" translate="label" type="text" sortOrder="11" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>FOO Email</label>
                    <validate>required-entry validate-email</validate>
                </field>
                <field id="bar_mail" translate="label" type="text" sortOrder="12" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>BAR Email</label>
                    <validate>required-entry validate-email</validate>
                </field>
            </group> 
         </section>
     </system>
 </config>

I now would like to be able to get all the fields of a section group, something like :

$Fields = $this->_scopeConfig->getFields('fooconfig/general',...);
foreach ($Fields as $Field) {
    $Entries = $this->_scopeConfig->getValue('fooconfig/general/'.$Field->getId(), \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

//do what needed here
}

Is there a possibility to do somehting like that?

Thank you for your help

0

There is no method for getting fields like getFields().

You can get all values of a group at once like following way:

$fieldsArray  = array('fooconfig/general/foo_mail','fooconfig/general/bar_mail');

foreach($fieldsArray as $field){
    $entries = $this->_scopeConfig->getValue($field, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
    //do your action
}

Hope, by this way you can get your requirements.

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.