Overview
There will likely come a point where you need more field types than what Lunar offers in the core. We’ve made adding your own a breeze and it’s the same process whether you want to add these to directly to your app or via an add on. Lunar will load up available field types via theAttributeManifest. This is a singleton which houses all the field types you can use. We currently have a handful in the core, with more being added in the future. If you need a field type that’s not here, speak with us first in case it’s in the pipeline.
Create Your Field Type Class
Each FieldType is it’s own class which implements theFieldType interface. So start by creating this class:
getValue
This will return the value from the attribute_date for display.
setValue($value)
The input value will be passed through here, so do any additional processing you need and then set the value property:
getLabel
Return the display label for the field type, used when displaying in the admin hub.
getConfig
Return an array of configuration, gets passed to the settings view and saved against the attribute when edited.
getSettingsView
Return the reference to the settings view. Used in the hub when editing an attribute of for field type.
getView
Return the reference to the view when editing in the hub. i.e. on the product edit screen.
Configuration
This should include any additional configuration your FieldType might need. If you need to store extra information that requires user input in the settings. You need to add them to theoption array like so:
Settings View
The settings view is what staff will see when they are creating an attribute with this field type. Here you can define any extra configuration your field type may need when displayed for editing. If your settings require input from the staff member, such as a text input or dropdown, these fields must be present in the config.Edit View
When a staff member is editing something such as a product, we need to be able to show the correct type of input for our field type. In this view we have access to the$field variable, which contains everything we need for data binding.
$language variable, which is generally used on translated attributes. This will be the language code such as en