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!
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With