Joomla 4 - How to add support for custom fields and fields group to own component

393 views
Skip to first unread message

Viper

unread,
Dec 14, 2021, 4:37:14 PM12/14/21
to Joomla! General Development
Does anyone have an idea how to achieve this? Old code with JHtmlSidebar::addEntry() in component helper just add an extra links under the main toolbar but not in left menu.

Glenn Arkell

unread,
Dec 14, 2021, 7:49:26 PM12/14/21
to Joomla! General Development
I've been playing with adding Custom Fields to a Dashboard in J4.  So I do this through the presets XML file 9administrator/components/com_mycomponent/presets/mycomponent.xml.  Then in the XML I have:

        <menuitem
                title="COM_CONTENT_MENUS_MANAGE"
                type="heading"
                icon="user-tag"
                class="class:user-tag"
                >
                <menuitem
                        title="COM_CONTENT_MENUS_WORKFLOW"
                        type="component"
                        element="com_workflow"
                        link="index.php?option=com_workflow&amp;view=workflows&amp;extension=com_mycomponent.positions"
                />

                <menuitem
                        title="MOD_MENU_FIELDS"
                        type="component"
                        element="com_fields"
                        link="index.php?option=com_fields&amp;view=fields&amp;context=com_ mycomponent .position"
                />

                <menuitem
                        title="MOD_MENU_FIELDS_GROUP"
                        type="component"
                        element="com_fields"
                        link="index.php?option=com_fields&amp;view=groups&amp;context=com_ mycomponent .position"
                />
        </menuitem>

</menu>

Hope this helps.  Cheers.

Glenn Arkell

unread,
Dec 14, 2021, 8:12:23 PM12/14/21
to Joomla! General Development
And you can add them into the manifest as a submenu:
                         <menu link="option=com_fields&amp;context=com_ mycomponent .position ">JGLOBAL_FIELDS</menu>
                         <menu link="option=com_fields&amp;view=groups&amp;context=com_ mycomponent .position ">JGLOBAL_FIELD_GROUPS</menu>
        </submenu>

Viper

unread,
Dec 15, 2021, 5:57:08 AM12/15/21
to Joomla! General Development
Yes, I seen this. But I don't know if this file is used anywhere except com_content and com_contact. At least adding `presets/mycomponent.xml` into component admin folder, adding this into component install file doesn't do anything.
Message has been deleted

Viper

unread,
Dec 15, 2021, 5:59:49 AM12/15/21
to Joomla! General Development
At the moment, this is the only way to add these menu items.

Glenn Arkell

unread,
Dec 15, 2021, 2:37:16 PM12/15/21
to Joomla! General Development
Yes that is how to add them to the side navigation menu structure, but to have them in a dashboard means you need to set up your components dashboard.  So your components menuitems are set above these "standard" menu items for workflow and custom fields.
So in your manifest you have the dashboard entry:
        <dashboards>
                <dashboard title="COM_MYCOMPONENT_DASHBOARD_TITLE" icon="icon-fas fa-books">COM_MYCOMPONENT_DASHBOARD_TITLE</dashboard>
        </dashboards>
Then you have the main menu item:
        <menu img="class:books" >
                        COM_ MYCOMPONENT
                        <params>
                                <dashboard>mycomponent</dashboard>
                        </params>
         </menu>
Don't forget to add the presets folder to the admin files section:
            <folder>presets</folder>
Then in your presets file called "mycomponent" you have:
<?xml version="1.0"?>
<menu
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="urn:joomla.org"
        xsi:schemaLocation="urn:joomla.org menu.xsd"
        >
        <menuitem
                title="COM_ MYCOMPONENT "
                type="heading"
                icon="books"
                class="class:books"
                >
                <menuitem
                        title="COM_ MYCOMPONENT_TITLE_BOOKS"
                        type="component"
                        element="com_ mycomponent "
                        link="index.php?option=com_ mycomponent &amp;view=books"
                        quicktask="index.php?option=com_ mycomponent &amp;task=book.add"
                        quicktask-title="COM_ MYCOMPONENT_MENUS_NEW_BOOK"
                />
              <menuitem . . . . . etc
 
                />

Then close off your components specific menu items and add the extra custom fields & workflow if required:
        </menuitem>        <menuitem

                title="COM_CONTENT_MENUS_MANAGE"
                type="heading"
                icon="user-tag"
                class="class:user-tag"
                >
                <menuitem
                        title="COM_CONTENT_MENUS_WORKFLOW"
                        type="component"
                        element="com_workflow"
                        link="index.php?option=com_workflow&amp;view=workflows&amp;extension=com_gausers.clubexec"

                />

                <menuitem
                        title="MOD_MENU_FIELDS"
                        type="component"
                        element="com_fields"
                        link="index.php?option=com_fields&amp;view=fields&amp;context=com_gausers.clubexec"

                />

                <menuitem
                        title="MOD_MENU_FIELDS_GROUP"
                        type="component"
                        element="com_fields"
                        link="index.php?option=com_fields&amp;view=groups&amp;context=com_gausers.clubexec"
                />
        </menuitem>

</menu>

This should then give you the dashboard icon beside your component main menu listing under components to access the dashboard just like the Content, Menus, and Users core components.
Hope this helps get you where you want to be.

Viper

unread,
Dec 17, 2021, 3:13:30 PM12/17/21
to Joomla! General Development
Very strange.
I see the dashboard icon near the main component menu item, but not a new menu items from component presets xml.

Glenn Arkell

unread,
Dec 17, 2021, 10:15:24 PM12/17/21
to Joomla! General Development
So what happens when you click the Dashboard icon?

Viper

unread,
Dec 18, 2021, 3:47:48 AM12/18/21
to Joomla! General Development
An empty dashboard opened with Add new item.
But I'm talking not about dashboard.
com_contact doesn't have a presets xml and fields menu in content.xml, but have Fields and Fields group in left menu.

Glenn Arkell

unread,
Dec 18, 2021, 8:32:17 PM12/18/21
to Joomla! General Development
Ok, let's go back to Q1:
a) do you want Custom Fields setup to be in the left navigation menu as elements in your components submenu, OR
b) do you want them within a Dashboard setup like com_users

If wanting option a) then you should be set with what was suggested earlier in the manifest.
If you wish to have a dashboard, then we can go through what's missing.

Viper

unread,
Dec 19, 2021, 2:38:34 AM12/19/21
to Joomla! General Development
Ahh! I see. Thanks for help.
Reply all
Reply to author
Forward
0 new messages