Widget definition for BE form fields in Magento

The general widget definition for BE form fields in Magento is:

<?xml version="1.0"?>
<widgets>
    <widget_identifier type="blochtype/like_in_normal_blocks" translate="name description" module="modulname">
        <name>Widgetname</name>
        <description>A useful description</description>
        <is_email_compatible>1</is_email_compatible>
        <parameters>
            <!-- field definition goes here -->
        </parameters>
    </widget_identifier>
</widgets>

The following snippets show how to define different form fields for the widget form:

  • Template selector:
    <template translate="label">
        <label>Template</label>
        <visible>1</visible>
        <type>select</type>
        <value>cms/widget/link/link_block.phtml</value>
        <values>
            <default translate="label">
                <value>cms/widget/link/link_block.phtml</value>
                <label>CMS Page Link Block Template</label>
            </default>
            <link_inline translate="label">
                <value>cms/widget/link/link_inline.phtml</value>
                <label>CMS Page Link Inline Template</label>
            </link_inline>
        </values>
    </template>
  • Fixed template:

    <template translate="label">
        <label>Template</label>
        <required>1</required>>
        <visible>0</visible>
        <type>text</type>
        <value>asksheldon_teaser/link.phtml</value>
    </template>
  • Text input:
    <column_count translate="label description">
        <visible>1</visible>
        <required>1</required>
        <label>Columncount</label>
        <description>Number of Colums</description>
        <type>text</type>
        <sort_order>1</sort_order>
    </column_count>
    
  • Enable / disable select:
    <enabled translate="label">
        <label>Enable</label>
        <frontend_type>select</frontend_type>
        <source_model>adminhtml/system_config_source_yesno</source_model>
        <sort_order>10</sort_order>
        <show_in_default>1</show_in_default>
        <show_in_website>1</show_in_website>
        <show_in_store>0</show_in_store>
    </enabled>
  • Multiselect (customer groups):

    <customer_groups translate="label comment">
        <label>Customer groups</label>
        <frontend_type>multiselect</frontend_type>
        <source_model>adminhtml/system_config_source_customer_group</source_model>
        <sort_order>11</sort_order>
        <show_in_default>1</show_in_default>
        <show_in_website>1</show_in_website>
        <show_in_store>0</show_in_store>
        <comment>Groups for Friends & Family discounts.</comment>
    </customer_groups>
  • Category Selector:
    <catid translate="label">
        <visible>1</visible>
        <required>1</required>
        <label>Category</label>
        <type>label</type>
        <helper_block>
            <type>adminhtml/catalog_category_widget_chooser</type>
            <data>
                <button translate="open">
                    <open>Select Category...</open>
                </button>
            </data>
        </helper_block>
    </catid>

    To determine the category ID and load the category in the widget block class, you can use this snippet:

    $iCategoryId = str_replace('category/', '', $this->getData('catid'));
    $oCategory   = Mage::getModel('catalog/category')->load($iCategoryId);

     

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.