Skip to content

Tutorial: Widget Category Management

Widget categories group the widgets shown in the Hyvä Admin Dashboard widget menu. You manage them by configuring the Hyva\AdminDashboardFramework\Model\Config\Widget\Converter class through etc/di.xml. This tutorial covers adding, removing, reordering, and renaming categories, plus changing the default.

Adding New Categories

To add a category, define a new <item> in the converter's categoryNames argument. The item name is the value you reference from hyva_dashboard_widget.xml, and each category carries an enabled flag, a label, and a sortOrder:

<type name="Hyva\AdminDashboardFramework\Model\Config\Widget\Converter">
    <arguments>
        <argument name="categoryNames" xsi:type="array">
            <!-- The item name is the value used in the hyva_dashboard_widget.xml configuration -->
            <item name="foo" xsi:type="array">
                <item name="enabled" xsi:type="boolean">true</item>
                <item name="label" xsi:type="string">Foo</item>
                <item name="sortOrder" xsi:type="number">500</item>
            </item>
        </argument>
    </arguments>
</type>

Removing Categories

To remove a category, set its enabled flag to false. You only need to specify the flag you are changing; the rest of the category definition is inherited:

<type name="Hyva\AdminDashboardFramework\Model\Config\Widget\Converter">
    <arguments>
        <argument name="categoryNames" xsi:type="array">
            <item name="sales" xsi:type="array">
                <item name="enabled" xsi:type="boolean">false</item>
            </item>
        </argument>
    </arguments>
</type>

Reordering Categories

To move a category, change its sortOrder to a number before, after, or between the sortOrder values of the other categories. Lower numbers appear first:

<type name="Hyva\AdminDashboardFramework\Model\Config\Widget\Converter">
    <arguments>
        <argument name="categoryNames" xsi:type="array">
            <item name="catalog" xsi:type="array">
                <item name="sortOrder" xsi:type="number">1</item>
            </item>
        </argument>
    </arguments>
</type>

Updating Category Names

To rename a category, change its label value:

<type name="Hyva\AdminDashboardFramework\Model\Config\Widget\Converter">
    <arguments>
        <argument name="categoryNames" xsi:type="array">
            <item name="system" xsi:type="array">
                <item name="label" xsi:type="string">Configuration</item>
            </item>
        </argument>
    </arguments>
</type>

Info

Category names are translated in the relevant template(s), so there is no need to update a category name just to translate it.

Changing the Default Category

To change which category is selected by default, update the defaultCategoryName argument to the name of the new default category:

<type name="Hyva\AdminDashboardFramework\Model\Config\Widget\Converter">
    <arguments>
        <argument name="defaultCategoryName" xsi:type="string">foo</argument>
    </arguments>
</type>

Warning

The default category MUST be enabled.