Skip to main content

Tutorial: Build your own custom field plugin - fields/owlimg.php

Written by Elisa Foltyn

This Joomla! Custom Field Plugin shows images from a selected folder in an "Owl Carousel". In this tutorial, I'll explain to you, how to build your own "Custom Field Plugin".

fields/owlimg.php

In the file fields/owlimg.php we will now create our field. Since we are using an existing field type and just customise it with our template the following code is sufficient:

<?php
/**
 * @package     Joomla.Plugin
 * @subpackage  Fields.Owlimg
 *
 * @copyright   Copyright (C) 2017 NAME. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

JFormHelper::loadFieldClass('folderlist');

class JFormFieldOwlimg extends JFormFieldFolderList
{
	public $type = 'Owlimg';
}


After the obligatory  <?php defined('_JEXEC') or die; we call the JForm Class with JFormHelper::loadFieldClass('folderlist');

You can find all the available JForm field types in the Joomla! documentation in this list:
https://docs.joomla.org/Standard_form_field_types/en

After JFormField the name of our plugin follows beginning with an uppercase letter so JFormFieldOwlimg. With extends, we say that we want to extend an existing class. In this case JFormFieldFolderList.

Inside the class, we define the public type which is Owlimg.

If we need a "special input field", we could create or define it now inside this class. But here we are using an existing JForm field. To change some attributes of the existing listfield, we will dive into the main file owlimg.php in the root of our plugin. 

It's definitely time we get together!