In Magento 2, I want to fetch group id from system.xml in my custom sourceModel
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
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();
 }
}
Explore related questions
See similar questions with these tags.