I am trying to get backend model class name from system.xml
Right now i am using this code.
magento/app/code/Company/Sso/etc/adminhtml/system.xml
<?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">
<system>
<section id="admin">
<group id="sso_saml" translate="label" sortOrder="100" showInDefault="1" showInWebsite="0" showInStore="0" >
<label>Single Sign on(SAML)</label>
<field id="is_enabled" translate="label comment" type="select" sortOrder="0" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Is Enabled SAML</label>
<comment>Enable Single Sign On</comment>
<source_model>MagentoConfigModelConfigSourceYesno</source_model>
</field>
</group>
</section>
</system>
Magento Code
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$structure = $objectManager->create('MagentoConfigModelConfigStructureFactory');
$field = $objectManager->create('MagentoConfigModelConfigStructure')->getElementByConfigPath('admin/sso_saml/is_enabled');
print json_encode($field->getData());
Output:
{"id":"is_enabled","path":"admin/sso_saml","_elementType":"field"}
But i need source_model, can anyone help?
2
Answers
Here is full solution after implementing Matt's solution.
You need to be in the adminhtml area in order to load the rest of the data:
e.g
You could potentially use
MagentoFrameworkAppState::emulateAreaCode
to fetch the data from within a non-admin context if necessary.