Practice Tests
You are configuring a new entry in etc/adminhtml/system.xml that is a select / dropdown type.
What must the class for the source model extend or implement?
A. \Magento\Framework\Data\OptionSourceInterface
B. \Magento\Backend\Model\AbstractSource
C. \Magento\Framework\Source\OptionInterface
D. \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
Answer A
for example: vendor\magento\module-authorizenet-acceptjs\etc\adminhtml\system.xml
<field id="payment_action" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
<label>Payment Action</label>
<source_model>Magento\AuthorizenetAcceptjs\Model\Adminhtml\Source\PaymentAction</source_model>
<config_path>payment/authorizenet_acceptjs/payment_action</config_path>
</field>
class PaymentAction implements \Magento\Framework\Data\OptionSourceInterface
interface OptionSourceInterface
{
/**
* Return array of options as value-label pairs
*
* @return array Format: array(array('value' => '<value>', 'label' => '<label>'), ...)
*/
public function toOptionArray();
}
References
Shortly speaking, the Source Model is a model of data that we can use for configuration.
Magento 2 Backend Configuration: Source Model (part 1/3)
Managing actions before and after saving
Magento 2 Backend Configuration: Backend Model (part 2/3)
The Frontend Model responsible for our fields view. We don’t mean changing the height/width of the input, but a non-standard fields for our non-standard configuration.
Magento 2 Backend Configuration: Frontend Model (part 3/3)