?
avatar grantg182
grantg182
20 Mar 2020

Steps to reproduce the issue

Created a plugin to add extra field to the Category edit page as I cannot use 'com_fields' Custom Fields for various reasons. Code as below for this. Field renders as expected.

categoryextension.xml:

<?xml version="1.0" encoding="UTF-8"?>
<form>
    <fields name="params">
        <fieldset name="category-icon" label="Icon">
            <field name="icon" type="text" default="icon-round" label="Category Icon" description="Enter the category icon" size="100" />
        </fieldset>
    </fields>
</form>

categoryextension.php

<?php
// no direct access
defined('_JEXEC') or die('Restricted access');

class plgContentCategoryExtension extends JPlugin
{

    /**
     * Load the language file on instantiation.
     *
     * @var boolean
     * @since 3.1
     */

    protected $autoloadLanguage = true;

    public function onContentPrepareForm($form, $data)
    {

        $app = JFactory::getApplication();
        $option = $app->input->get('option');
        $view = $app->input->get('view');

        switch ($option) {

            case 'com_categories':

                switch ($view) {

                    case 'category':

                        if ($app->isAdmin()) {

                            JForm::addFormPath(__DIR__ . '/forms');

                            $form->loadFile('categoryextension', false);

                        }

                        return true;
                }

            return true;
        }

        return true;

    }

}

Expected result

Custom field is rendered. Data is saved to the database.

Actual result

Custom field is rendered. Data is NOT saved to the database.

System information (as much as possible)

3.9.8

Additional comments

Here's a very old blog post about this exact issue, in Joomla 2.5 and 3.0, but the code in com_categories edit.php has changed a lot since then.... https://techjoomla.com/developers-blogs/joomla-development/adding-custom-fields-to-joomla-categories-in-joomla-25

avatar grantg182 grantg182 - open - 20 Mar 2020
avatar joomla-cms-bot joomla-cms-bot - change - 20 Mar 2020
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 20 Mar 2020
avatar grantg182 grantg182 - change - 20 Mar 2020
The description was changed
avatar grantg182 grantg182 - edited - 20 Mar 2020
avatar SharkyKZ
SharkyKZ - comment - 20 Mar 2020

Don't use the view to determine which form it is. It will get lost when saving the form. Instead use form name.

public function onContentPrepareForm(JForm $form, $data)
{
	if ($form->getName() !== 'com_categories.categorycom_content')
	{
		return;
	}

	JFormHelper::addFormPath(__DIR__ . '/forms');

	$form->loadFile('categoryextension', false);
}
avatar SharkyKZ SharkyKZ - change - 20 Mar 2020
Status New Expected Behaviour
Closed_Date 0000-00-00 00:00:00 2020-03-20 06:52:39
Closed_By SharkyKZ
avatar joomla-cms-bot joomla-cms-bot - change - 20 Mar 2020
Status Expected Behaviour Closed
Closed_Date 2020-03-20 06:52:39 2020-03-20 06:52:40
Closed_By SharkyKZ joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - close - 20 Mar 2020
avatar joomla-cms-bot
joomla-cms-bot - comment - 20 Mar 2020

Set to "closed" on behalf of @SharkyKZ by The JTracker Application at issues.joomla.org/joomla-cms/28402

avatar SharkyKZ
SharkyKZ - comment - 20 Mar 2020

Closing as issue is in your code.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/28402.

Add a Comment

Login with GitHub to post a comment