Skip to main content

Categoryj2commerce Form Field

Categoryj2commerceField is a SpacerField subclass that renders a Bootstrap 5 accordion on the Joomla category edit form. Each accordion panel contains a section of J2Commerce category configuration — such as display settings, product element visibility, default values, and filters. Core panels are generated by CategoryHelper::getCoreCategoryFormData(). App plugins contribute additional panels via the onJ2CommerceAfterDisplayCategoryForm event.

This field produces no form input. It exists purely to inject a rich UI component into an existing Joomla core form.

Key Classes

ClassFilePurpose
Categoryj2commerceFieldadministrator/components/com_j2commerce/src/Field/Categoryj2commerceField.phpRenders the accordion container
CategoryHelperadministrator/components/com_j2commerce/src/Helper/CategoryHelper.phpgetCoreCategoryFormData() — returns core accordion panel definitions
PluginHelper (J2Commerce)administrator/components/com_j2commerce/src/Helper/PluginHelper.phpeventWithAppData() — collects plugin-contributed panels

Architecture

Core Accordion Panels

CategoryHelper::getCoreCategoryFormData() returns the following panels, ordered by the ordering key:

Element keyLanguage nameForm XMLOrdering
category_displayCOM_J2COMMERCE_CATEGORY_DISPLAY_SETTINGSforms/category_display.xml10
category_elementsCOM_J2COMMERCE_CATEGORY_PRODUCT_ELEMENTSforms/category_elements.xml20
category_defaultsCOM_J2COMMERCE_CATEGORY_PRODUCT_DEFAULTSforms/category_defaults.xml30
category_filtersCOM_J2COMMERCE_CATEGORY_FILTER_CONFIGforms/category_filters.xml40
category_subcategoriesCOM_J2COMMERCE_CATEGORY_SUBCATEGORY_SETTINGSforms/category_subcategories.xml50

Each panel's form fields are bound with the existing category's params.j2commerce.* values before rendering.

Form Field Naming Convention

All fields rendered inside the accordion use jform[params][j2commerce] as the control prefix. For example, a field named products_per_page in a category form panel submits as:

jform[params][j2commerce][products_per_page]

The Joomla category model stores this under params in #__categories.

Plugin Event: onJ2CommerceAfterDisplayCategoryForm

App plugins can inject additional accordion panels by handling this event:

DetailValue
Event nameonJ2CommerceAfterDisplayCategoryForm
Event methodPluginHelper::eventWithAppData('AfterDisplayCategoryForm', ...)
Plugin groupj2commerce
Return formatArray with element key (required) + optional name, description, image, form_xml, html, data, ordering

Adding a Custom Category Settings Panel

// File: plugins/j2commerce/app_yourplugin/src/Extension/AppYourPlugin.php

declare(strict_types=1);

namespace J2Commerce\Plugin\J2Commerce\App\YourPlugin\Extension;

use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Event\Event;
use Joomla\Event\SubscriberInterface;

class AppYourPlugin extends CMSPlugin implements SubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
'onJ2CommerceAfterDisplayCategoryForm' => 'onAfterDisplayCategoryForm',
];
}

public function onAfterDisplayCategoryForm(Event $event): void
{
// Return an app data array; the 'element' key is required.
$event->setArgument('result', [
[
'element' => 'app_yourplugin',
'name' => 'PLG_J2COMMERCE_APP_YOURPLUGIN_TITLE',
'description' => 'PLG_J2COMMERCE_APP_YOURPLUGIN_CAT_SETTINGS_DESC',
'image' => '/media/plg_j2commerce_app_yourplugin/images/icon.png',
'form_xml' => JPATH_PLUGINS . '/j2commerce/app_yourplugin/forms/category.xml',
'data' => [], // Pre-bound data if any
'ordering' => 60,
],
]);
}
}

App Data Array Keys

KeyTypeRequiredDescription
elementstringYesUnique element identifier. Used in DOM IDs and CSS classes.
namestringNoLanguage key for the panel heading. Falls back to PLG_J2COMMERCE_{ELEMENT}.
descriptionstringNoLanguage key for the panel sub-heading.
imagestringNoAbsolute URL to the panel icon image.
form_xmlstringNoAbsolute filesystem path to a Joomla form XML file. Rendered via Form::renderFieldset('basic').
htmlstringNoRaw HTML to render if form_xml is absent or the file does not exist.
dataarrayNoData to bind to the form before rendering.
orderingintNoSort position. Lower numbers appear first. Defaults to 100.

Accordion Rendering Details

  • The first panel ($index === 0) renders open by default (accordion-button without collapsed, aria-expanded="true", and show class on the collapse element).
  • All other panels are collapsed.
  • The accordion container uses id="j2commerce-category-accordion" and each panel targets its sibling panels via data-bs-parent, making it a true single-open accordion.
  • Panel images are rendered at medium and larger breakpoints only (d-none d-lg-inline-block d-md-block).

XML Usage

The field is placed inside a Joomla category parameters form. Because J2Commerce injects into Joomla's com_categories component form, the field must be declared in a form that is loaded via the onContentPrepareForm event:

<!-- File: plugins/j2commerce/app_bootstrap5/forms/category_j2commerce.xml (example) -->

<form addfieldprefix="J2Commerce\Component\J2commerce\Administrator\Field">
<fieldset name="j2commerce_settings"
label="COM_J2COMMERCE_CATEGORY_J2COMMERCE_TAB">
<field
name="j2commerce"
type="Categoryj2commerce"
hiddenLabel="true"
label="COM_J2COMMERCE_CATEGORY_J2COMMERCE_SETTINGS"
/>
</fieldset>
</form>

XML Attributes

AttributeTypeDefaultDescription
typestringMust be Categoryj2commerce
hiddenLabelboolfalseTypically set to true since the accordion has its own headings
labelstringLanguage key; hidden but required by the form system

The field ignores all other XML attributes — its entire output is determined by CategoryHelper and the plugin event.

Empty State

If no core panels and no plugin panels are returned, the field renders:

<div class="alert alert-info">COM_J2COMMERCE_CATEGORY_TAB_NO_APPS</div>