Tutorial: Custom Configurable Inputs
While a set of input elements are provided out-of-the-box, it is certainly feasible for developers to want to create their own custom input types to better suit the needs of their widgets and/or admin users.
- Add a new child block to the
widget-form.inputsblock inhyva_dashboard_widget.xml. - Create the template file to handle the rendering of the custom input type.
- The widget type object is available from the block via
$block->getData('widget')or$block->getWidget() - The widget instance object is available from the block via
$block->getData('widget_instance')or$block->getWidgetInstance()- The widget instance object will be
nullwhen the input is not associated with a particular widget instance
- The widget instance object will be
- The input name is available from the block via
$block->getData('input_name')or$block->getInputName()and contains the value specified for thelabel - The input configuration is available from the block via
$block->getData('input_config')or$block->getInputConfig() - The input ID is available from the block via
$block->getData('input_id')or$block->getInputId()
- The widget type object is available from the block via
- Use the custom input type name when defining the input
typein the widget's PHP class.
Input Type Names
When creating a custom input type, the name of the block defined in layout XML must match the pattern
input.{{TYPE}} in order for Magento to be able to automatically handle the rendering of the input template.
Dynamic Row Inputs
In some instances it may also be necessary to handle inputs differently when they are rendered as part of a dynamic
row input. In these cases the block name used in layout XML should follow the pattern input.dynamic-rows.{{TYPE}}.