How to Add Configuration Options in Joomla Component

The Joomla allows the use of parameters stored in each component. The fields for the configuration options are stored in the XML file located at admin/config.xml.

This file is read by the com_config component of the Joomla core.

Step 1: XML File

config.xml

<?xml version="1.0" encoding="utf-8"?>
<config>
<fieldset name="planets" label="Planets">
<field
name="show_category"
type="radio"
label="JCATEGORY"
default="0"
 layout="joomla.form.field.radio.switcher">
<option value="0">JHIDE</option>
<option value="1">JSHOW</option>
</field>
</fieldset>
</config>

Step 2: View File

src/View/Planets/HtmlView.php

Additionally, you need to add the Preferences (Options) button in a toolbar in the addToolBar() method. You can add this in all the back-end list views.

ToolBarHelper::preferences('com_planets');

How to Get Configuration Values

You need to get a component params for use at different places in the code. To access component params in the component itself, you can use Factory::getApplication() like below:

$app = Factory::getApplication();
$params = $app->getParams();
$param = $params->get('show_category');

To access the component params from another component, you can use ComponentHelper::getParams() like below:

$content_params = ComponentHelper::getParams('com_content');
$show_date = $content_params->get('show_create_date');

Default Configuration, Item Configuration, Menu Configuration

In Joomla, configuration parameters for extensions can be set at many levels.

  1. The default configuration is stored in admin/config.xml file at the administrator part of the component.
  2. At the menu level, it is stored in default.xml file in the tmpl folder of the front-end view.
  3. Administrator can control the display in the front end by specifying a global configuration parameter or override this setting on an individual item basis. To enable this, you need to add a params field in the database, which will be a string in JSON format.