I need help in adding extra fields to Joomla categories(not article) in my custom component categories and I didnt find any documentation for that. I want to add a time field to categories. I tried to use fieldsattach but it is giving lots of errors. So I started building my own plugin following some joomla docs but i am not able to add extra fields into categories. This is what I tried till now. I created a plugin xml file named plg_bfquiz_catextras.xml
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.1" type="plugin" group="categories">
<name>plg_bfquiz_catextras</name>
<author>Joomla! Project</author>
<creationDate>January 2021</creationDate>
<copyright>Copyright (C) 2021 - 2022 . All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail></authorEmail>
<authorUrl></authorUrl>
<version>3.1.0</version>
<description>PLG_BFQUIZ_CATEXTRAS_XML_DESCRIPTION</description>
<files>
<filename plugin="plg_bfquiz_catextras">plg_bfquiz_catextras.php</filename>
<folder>forms</folder>
<filename>index.html</filename>
</files>
<languages>
<language tag="en-GB">en-GB.plg_bfquiz_catextras.ini</language>
<language tag="en-GB">en-GB.plg_bfquiz_catextras.sys.ini</language>
</languages>
</extension>
Then in plugin plg_bfquiz_catextras.php file
<?php
// no direct access
defined ('_JEXEC') or die;
class plgCategoriesBFQuizCatextras extends JPlugin
{
/**
* Load the language file on instantiation.
* Note this is only available in Joomla 3.1 and higher.
* If you want to support 3.0 series you must override the constructor
*
* @var boolean
* @since <your version>
*/
protected $autoloadLanguage = true;
/**
* Prepare form and add my field.
*
* @param JForm $form The form to be altered.
* @param mixed $data The associated data for the form.
*
* @return boolean
*
* @since <your version>
*/
function onContentPrepareForm($form, $data)
{
$app = JFactory::getApplication();
$option = $app->input->get('option');
switch($option)
{
case 'com_bfquiz' :
if ($app->isClient('administrator'))
{
JForm::addFormPath(__DIR__ . '/forms');
$form->loadFile('catxtras', false);
}
return true;
}
return true;
}
}
?>
And finally I have a forms folder inside which there is a file named catextras.xml with content
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="params">
<fieldset name="params" label="PLG_BFQUIZ_CATEXTRAS_FIELDSET_LABEL">
<field
name="cat_time"
type="integer"
label="PLG_BFQUIZ_CATEXTRAS_TIME"
/>
</fieldset>
</fields>
</form>
I know I am doing some mistake but I am unable to point it out. Need help from Joomla Experts.