source_model / backend_model / frontend_model

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>

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


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)


电子邮件地址不会被公开。 必填项已用*标注