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;
}
}
Custom field is rendered. Data is saved to the database.
Custom field is rendered. Data is NOT saved to the database.
3.9.8
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
Labels |
Added:
?
|
Status | New | ⇒ | Expected Behaviour |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2020-03-20 06:52:39 |
Closed_By | ⇒ | SharkyKZ |
Status | Expected Behaviour | ⇒ | Closed |
Closed_Date | 2020-03-20 06:52:39 | ⇒ | 2020-03-20 06:52:40 |
Closed_By | SharkyKZ | ⇒ | joomla-cms-bot |
Set to "closed" on behalf of @SharkyKZ by The JTracker Application at issues.joomla.org/joomla-cms/28402
Closing as issue is in your code.
Don't use the view to determine which form it is. It will get lost when saving the form. Instead use form name.