How do you change form categories in Joomla?

I am working on creating a small plugin for changing category forms (in the category view of adding / editing) in Joomla.

I was able to use the tutorial on the Joomla website to change forms in user profiles, articles and menus; however, the categories do not seem to work properly.

This code that I use:

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 it looks like this:

 <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 on what I am doing wrong will be greatly appreciated! As I said, it will work with any other type of content, for example, so that it works on the menu, you just need to change the "name" in the code.

thanks!

+6
source share
2 answers

In fact, there is an error in Joomla 2.5 due to which the form fields are not displayed on the "Edit Category" page. We recently added a blog on our website that 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 was sent for Joomla

+4
source

I created a test bench and created a similar plugin. I repeated the value of $ form-> getName () and it appeared as "com_categories.categorycom_content"

It is best to assume that since categories can be used in several contexts, the component is added to the end.

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

+2
source

Source: https://habr.com/ru/post/894929/


All Articles