Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you modify Category Forms in Joomla?

I'm working on creating a small plugin to modify the Category Forms (on the add/edit category view) in Joomla.

I was able to use the tutorial on Joomla's site to modify the forms on User Profiles, Articles, and Menus; however, Categories do not seem to work properly.

This the code that I am using:

defined('JPATH_BASE') or die;

class plgContentCategoryType extends JPlugin {

    function onContentPrepareForm($form, $data) {

        // Load plugin language
        $lang = JFactory::getLanguage();
        $lang->load('plg_content_categorytype', JPATH_ADMINISTRATOR);

        if (!($form instanceof JForm)) {
            $this->_subject->setError('JERROR_NOT_A_FORM');
            return false;
        }

        // Check we are manipulating a valid form.
        if (!in_array($form->getName(), array('com_categories.category'))) {
            return true;
        }

        if ($form->getName()=='com_categories.category') {      
            // Add the fields to the form.
            JForm::addFormPath(dirname(__FILE__).'/forms');
            $form->loadFile('categorytype', false);
        }


    }

 }

and this is what the form XML looks like:

<form>
    <fields name="params">

        <fieldset name="categorytype" label="PLG_CONTENT_CATEOGRYTYPE_FIELDSET_LABEL">

            <field name="category_type" type="list" label="PLG_CONTENT_CATEGORYTYPE_LABEL" description="PLG_CONTENT_CATEGORYTYPE_DESC">
                <option value=""></option>
                <option value="features">PLG_CONTENT_CATEGORYTYPE_FEATURES</option>
                <option value="columns">PLG_CONTENT_CATEGORYTYPE_COLUMNS</option>
                <option value="spotlights">PLG_CONTENT_CATEGORYTYPE_SPOTLIGHTS</option>
                <option value="slices">PLG_CONTENT_CATEGORYTYPE_SLICES</option>
                <option value="news">PLG_CONTENT_CATEGORYTYPE_NEWS</option>
            </field>

        </fieldset>

    </fields>
</form>

Any help in what I'm doing wrong would be greatly appreciated! Like I said, it will work on any other type of content, for instance, for it to work on menu's, just have to change the 'name' in the code.

thanks!

like image 920
David Barratt Avatar asked Aug 12 '11 17:08

David Barratt


2 Answers

Actually there is a Bug in Joomla 2.5 due to which the form fields are not rendered on the Edit Category page. We recently Added a blog on our site which has a fix for this.. You can read it here http://techjoomla.com/joomla-development/adding-custom-fields-to-joomla-categories-in-joomla-25.html

A patch has been submitted for this to Joomla

like image 128
Parth Lawate Avatar answered Dec 25 '22 09:12

Parth Lawate


I set up a testbed and created a similar plugin. I echoed out the value of $form->getName() and it came out as 'com_categories.categorycom_content'

Best guess from this is that as categories can be used in multiple contexts that the component is appended on the end.

So, in the two lines where you have 'com_categories.category', replace with 'com_categories.categorycom_content' and it works.

like image 24
Dean Marshall Avatar answered Dec 25 '22 09:12

Dean Marshall