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

2 Answers 2


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.


I might be a bit late to the show, but here's the answer anyway.

To get all the fields of a group you just need to call \Magento\Framework\App\Config\ScopeConfigInterface::getValue and pass the section_name/group_name as the path (do not pass the field id).

So in your case, you need to

$fields = $this->scopeConfig->getValue('fooconfig/general');
foreach ($fields as $field => $value) {
    // do what is needed here
    // Also notice that the getValue returns 
    // the field and value as a key-value pair 
    // when you call it like this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.