6

I am looking for some information about how to create a custom field type for Joomla 3.7 core custom fields.

Can anyone point me in the direction of a tutorial, an example of anything that may help with the process? I couldn't find official documentation on that.

Please note I am not talking about adding the field to an article, I am talking about creating a new type of field that can be selected from the custom fields component.


I figured it is just a plugin, so I went to copy a core existing one to then expand on that.

However I copied the imagelist, renamed it all to newimagelist, installed all without problem. Created a new field, went into an article, but the newly created field which is just a copy doesn't behave same way. The list dropdown doesn't work. Any ideas?

1
  • 1
    You might find some info in Digital Peak's presentation at Joomladay Germany last year about creating a custom field for Joomla! joomla.digital-peak.com/images/blog/… Commented Aug 3, 2017 at 11:38

3 Answers 3

2

It seems that fields are simply plugins of type fields. Copy the text folder from /plugins/fields, to a new folder, text2 and change the names of the files inside the text-folder to text2.php and text.xml, and /tmpl/text2.php. In text2.xml there is a reference to the plugin name, update this as well, like:

<files> <filename plugin="text2">text2.php</filename> <folder>params</folder> <folder>tmpl</folder> </files> 

Now you are ready to use the discover - tool in the joomla administrator, to discover the new plugin. Go to yoursite/administrator/ and find the menu extensions/manage/discover. Click discover, the new plugin should be listed. Install the new plugin. Afterwards, find the new plugin in extensions/manage, and enable it.

Now you should be able to add a new custom field for eg. an article, using your brand new, custom, self made field...

There is a lot of info about writing your own plugin, eg:

https://docs.joomla.org/J3.x:Creating_a_Plugin_for_Joomla

1

You can copy one of the fields in:

\libraries\joomla\form\fields

to:

\components\com_yourcomponent\models\forms\fields

and rename the copied field. Then change data of your new custom filed.

2
  • What if we want a new field to be available within com_content. If I duplicate a .php file from \libraries\joomla\form\fields and rename it and the contents it does nothing. Commented Aug 8, 2020 at 16:27
  • Ah I see we need to create a plugin Commented Aug 8, 2020 at 16:28
0

From what I understand, the custom field type references a system field type of the same name. So when you copied the custom field plugin and renamed it, it now referenced a system field type that didn't exist.

I'm looking at doing the same thing, but it's a lot more work than just creating a plugin.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.