Working with source models
Magento works with a lot of dropdown fields that you can select in the forms of the application. We can see dropdowns in the configuration, product, customer, and many more pages.
Magento has a system to set the options of the dropdown and multiselect fields. Magento uses a model that returns the values and labels to render the options of a dropdown or multiselect field. These models are called source models.
In this recipe, we will see which source models Magento uses and how we can create a custom source model for a custom configuration field.
Getting ready
In this recipe, we will extend the Packt_HelloWorld
module that we created in the previous recipes. Make sure you have the right version installed for this recipe.
How to do it...
The following steps describe how you can create your custom source models for your custom form fields:
First we will create an extra field in the system configuration to run some tests. The following code adds a new field to the
HelloWorld...