1

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.

0

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

Magento\Framework\Data\Form\Element\AbstractElement

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();
    }
}
| 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.