In Magento 2, I want to fetch group id from system.xml in my custom sourceModel

enter image description here

But I am unable to find a solution online.

Please do let me know if it's possible or not.

I know there's an alternate solution to create 2 separate source Models for this purpose but I want to use only one.

1 Answer 1


Yes you can. The config fields default html are created from function getElementHtml defined the class


The input field name contains the section, group and field name as well. You can make use of function getName defined in the above class to get the group name.

For example in my source model class

class Education extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
    protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
        $name = $element->getName();
        // result will be => groups[group_name][fields][field_name]
        //do your logic
        return $element->getElementHtml();

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.