Defining custom form field types
We have a lot of Joomla! Standard Form fields and they should be enough for most projects, but at some point, you might need to create your own form fields to extend some functionality of your form. In Joomla!, this is as easy as extending the FormField
class.
To learn how to do this, we’ll recreate our project selector from the previous section using a custom form field. This field will be a select dropdown where the user can choose a project from a list.
First, we need to extend the FormField
class. This class is the one from which all Joomla! fields are created, and it provides all the required methods that allow Joomla! to show the fields defined in the XML forms.
So, let’s start creating our new field. Create the src/component/admin/src/Fields/ProjectField.php
field with the following content:
<?php namespace Piedpiper\Component\Spm\Administrator\Fields; use Joomla\CMS\Form\Field\ListField; class PiedpiperFormFieldProject...