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.

asked Jun 12, 2020 at 18:43

1 Answer 1

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();
 }
}
answered Jun 12, 2020 at 20:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.