I have created a module with custom system config entries :


<?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">
         <tab id="mainconfig" translate="label" sortOrder="1">
             <label>Mine Special</label>
         <section id="fooconfig" translate="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
             <label>FOO Configuration</label>

            <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 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>

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


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.

| improve this answer | |

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.