Skip to content

Commit e7534e0

Browse files
authored
[6.0] Numbers custom fields plugin (joomla#43974)
* First draft for numbers custom field plugin * Apply suggestions from code review * Apply suggestions from code review * added install sql and removed unused field param * updated copyright year * Update plugins/fields/number/tmpl/number.php * Added update sql and currency formatting option * I've added update sql and also implemented a currency formatting option to display the number as a currency. * cleaned up language strings * Removed unused language strings and changed mistakes and mismatches in naming. Also improved some text * Fixed years to 2025 and version number to be in line with joomla version * Alpha sorted the strings * fixed stupid mistake. * updated sql files to include all the default params settings * changed indentation * fix sorting of field params * Update administrator/language/en-GB/plg_fields_number.ini * Update administrator/language/en-GB/plg_fields_number.ini * removed unnecessary description * Changed update SQL file to own file and reverted changes to other file * Update administrator/language/en-GB/plg_fields_number.ini * removed unnecessary descriptions * removed unneccessary descriptions * removed more unnecessary descriptions and added default in the params file * Update administrator/components/com_admin/sql/updates/postgresql/6.0.0-2024-08-24.sql * changed sql name * Update 6.0.0-2024-08-24.sql * Rename 6.0.0-2024-08-24.sql to 6.0.0-2025-08-17.sql * Rename 6.0.0-2024-08-24.sql to 6.0.0-2025-08-17.sql
1 parent a9b20c8 commit e7534e0

File tree

11 files changed

+323
-16
lines changed

11 files changed

+323
-16
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `locked`, `manifest_cache`, `params`, `custom_data`, `ordering`, `state`) VALUES
2+
(0, 'plg_fields_number', 'plugin', 'number', 'fields', 0, 1, 1, 0, 1, '', '{"min":"1.0","max":"100.0","step":"0.1","currency":"0","position":"0","decimals":"2"}', '', -1, 0);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "locked", "manifest_cache", "params", "custom_data", "ordering", "state") VALUES
2+
(0, 'plg_fields_number', 'plugin', 'number', 'fields', 0, 1, 1, 0, 1, '', '{"min":"1.0","max":"100.0","step":"0.1","currency":"0","position":"0","decimals":"2"}', '', -1, 0);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; Joomla! Project
2+
; (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
3+
; License GNU General Public License version 2 or later; see LICENSE.txt
4+
; Note : All ini files need to be saved as UTF-8
5+
6+
PLG_FIELDS_NUMBER="Fields - Number"
7+
PLG_FIELDS_NUMBER_LABEL="Number (%s)"
8+
PLG_FIELDS_NUMBER_PARAMS_CURRENCY_LABEL="Format as Currency"
9+
PLG_FIELDS_NUMBER_PARAMS_DECIMALS_LABEL="Number of Decimals"
10+
PLG_FIELDS_NUMBER_PARAMS_MAX_DESC="Maximum value that can be chosen (only limits the up/down arrows)."
11+
PLG_FIELDS_NUMBER_PARAMS_MAX_LABEL="Maximum"
12+
PLG_FIELDS_NUMBER_PARAMS_MIN_DESC="Minimum value that can be chosen (only limits the up/down arrows)."
13+
PLG_FIELDS_NUMBER_PARAMS_MIN_LABEL="Minimum"
14+
PLG_FIELDS_NUMBER_PARAMS_POSITION_LABEL="Symbol Position"
15+
PLG_FIELDS_NUMBER_PARAMS_POSITION_OPTION_AFTER="After"
16+
PLG_FIELDS_NUMBER_PARAMS_POSITION_OPTION_BEFORE="Before"
17+
PLG_FIELDS_NUMBER_PARAMS_STEP_LABEL="Step Increment"
18+
PLG_FIELDS_NUMBER_PARAMS_SYMBOL_LABEL="Currency Symbol"
19+
PLG_FIELDS_NUMBER_XML_DESCRIPTION="This plugin lets you create new fields of type 'number' in any extensions where custom fields are supported."
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
; Joomla! Project
2+
; (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
3+
; License GNU General Public License version 2 or later; see LICENSE.txt
4+
; Note : All ini files need to be saved as UTF-8
5+
6+
PLG_FIELDS_NUMBER="Fields - Number"
7+
PLG_FIELDS_NUMBER_XML_DESCRIPTION="This plugin lets you create new fields of type 'number' in any extensions where custom fields are supported."

installation/sql/mysql/base.sql

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,15 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`,
299299
(0, 'plg_fields_list', 'plugin', 'list', 'fields', 0, 1, 1, 0, 1, '', '', '', 7, 0),
300300
(0, 'plg_fields_media', 'plugin', 'media', 'fields', 0, 1, 1, 0, 1, '', '', '', 8, 0),
301301
(0, 'plg_fields_note', 'plugin', 'note', 'fields', 0, 1, 1, 0, 1, '', '{"class":"alert alert-info","heading":"h4"}', '', 9, 0),
302-
(0, 'plg_fields_radio', 'plugin', 'radio', 'fields', 0, 1, 1, 0, 1, '', '', '', 10, 0),
303-
(0, 'plg_fields_sql', 'plugin', 'sql', 'fields', 0, 1, 1, 0, 1, '', '', '', 11, 0),
304-
(0, 'plg_fields_subform', 'plugin', 'subform', 'fields', 0, 1, 1, 0, 1, '', '', '', 12, 0),
305-
(0, 'plg_fields_text', 'plugin', 'text', 'fields', 0, 1, 1, 0, 1, '', '', '', 13, 0),
306-
(0, 'plg_fields_textarea', 'plugin', 'textarea', 'fields', 0, 1, 1, 0, 1, '', '{"rows":10,"cols":10,"maxlength":"","filter":"\\\\Joomla\\\\CMS\\\\Component\\\\ComponentHelper::filterText"}', '', 14, 0),
307-
(0, 'plg_fields_url', 'plugin', 'url', 'fields', 0, 1, 1, 0, 1, '', '', '', 15, 0),
308-
(0, 'plg_fields_user', 'plugin', 'user', 'fields', 0, 1, 1, 0, 1, '', '', '', 16, 0),
309-
(0, 'plg_fields_usergrouplist', 'plugin', 'usergrouplist', 'fields', 0, 1, 1, 0, 1, '', '', '', 17, 0),
302+
(0, 'plg_fields_number', 'plugin', 'number', 'fields', 0, 1, 1, 0, 1, '', '{"min":"1.0","max":"100.0","step":"0.1","currency":"0","position":"0","decimals":"2"}', '', 10, 0),
303+
(0, 'plg_fields_radio', 'plugin', 'radio', 'fields', 0, 1, 1, 0, 1, '', '', '', 11, 0),
304+
(0, 'plg_fields_sql', 'plugin', 'sql', 'fields', 0, 1, 1, 0, 1, '', '', '', 12, 0),
305+
(0, 'plg_fields_subform', 'plugin', 'subform', 'fields', 0, 1, 1, 0, 1, '', '', '', 13, 0),
306+
(0, 'plg_fields_text', 'plugin', 'text', 'fields', 0, 1, 1, 0, 1, '', '', '', 14, 0),
307+
(0, 'plg_fields_textarea', 'plugin', 'textarea', 'fields', 0, 1, 1, 0, 1, '', '{"rows":10,"cols":10,"maxlength":"","filter":"\\\\Joomla\\\\CMS\\\\Component\\\\ComponentHelper::filterText"}', '', 15, 0),
308+
(0, 'plg_fields_url', 'plugin', 'url', 'fields', 0, 1, 1, 0, 1, '', '', '', 16, 0),
309+
(0, 'plg_fields_user', 'plugin', 'user', 'fields', 0, 1, 1, 0, 1, '', '', '', 17, 0),
310+
(0, 'plg_fields_usergrouplist', 'plugin', 'usergrouplist', 'fields', 0, 1, 1, 0, 1, '', '', '', 18, 0),
310311
(0, 'plg_filesystem_local', 'plugin', 'local', 'filesystem', 0, 1, 1, 0, 1, '', '{}', '', 1, 0),
311312
(0, 'plg_finder_categories', 'plugin', 'categories', 'finder', 0, 1, 1, 0, 1, '', '', '', 1, 0),
312313
(0, 'plg_finder_contacts', 'plugin', 'contacts', 'finder', 0, 1, 1, 0, 1, '', '', '', 2, 0),

installation/sql/postgresql/base.sql

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,15 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder",
305305
(0, 'plg_fields_list', 'plugin', 'list', 'fields', 0, 1, 1, 0, 1, '', '', '', 7, 0),
306306
(0, 'plg_fields_media', 'plugin', 'media', 'fields', 0, 1, 1, 0, 1, '', '', '', 8, 0),
307307
(0, 'plg_fields_note', 'plugin', 'note', 'fields', 0, 1, 1, 0, 1, '', '{"class":"alert alert-info","heading":"h4"}', '', 9, 0),
308-
(0, 'plg_fields_radio', 'plugin', 'radio', 'fields', 0, 1, 1, 0, 1, '', '', '', 10, 0),
309-
(0, 'plg_fields_sql', 'plugin', 'sql', 'fields', 0, 1, 1, 0, 1, '', '', '', 11, 0),
310-
(0, 'plg_fields_subform', 'plugin', 'subform', 'fields', 0, 1, 1, 0, 1, '', '', '', 12, 0),
311-
(0, 'plg_fields_text', 'plugin', 'text', 'fields', 0, 1, 1, 0, 1, '', '', '', 13, 0),
312-
(0, 'plg_fields_textarea', 'plugin', 'textarea', 'fields', 0, 1, 1, 0, 1, '', '{"rows":10,"cols":10,"maxlength":"","filter":"\\\\Joomla\\\\CMS\\\\Component\\\\ComponentHelper::filterText"}', '', 14, 0),
313-
(0, 'plg_fields_url', 'plugin', 'url', 'fields', 0, 1, 1, 0, 1, '', '', '', 15, 0),
314-
(0, 'plg_fields_user', 'plugin', 'user', 'fields', 0, 1, 1, 0, 1, '', '', '', 16, 0),
315-
(0, 'plg_fields_usergrouplist', 'plugin', 'usergrouplist', 'fields', 0, 1, 1, 0, 1, '', '', '', 17, 0),
308+
(0, 'plg_fields_number', 'plugin', 'number', 'fields', 0, 1, 1, 0, 1, '', '{"min":"1.0","max":"100.0","step":"0.1","currency":"0","position":"0","decimals":"2"}', '', 10, 0),
309+
(0, 'plg_fields_radio', 'plugin', 'radio', 'fields', 0, 1, 1, 0, 1, '', '', '', 11, 0),
310+
(0, 'plg_fields_sql', 'plugin', 'sql', 'fields', 0, 1, 1, 0, 1, '', '', '', 12, 0),
311+
(0, 'plg_fields_subform', 'plugin', 'subform', 'fields', 0, 1, 1, 0, 1, '', '', '', 13, 0),
312+
(0, 'plg_fields_text', 'plugin', 'text', 'fields', 0, 1, 1, 0, 1, '', '', '', 14, 0),
313+
(0, 'plg_fields_textarea', 'plugin', 'textarea', 'fields', 0, 1, 1, 0, 1, '', '{"rows":10,"cols":10,"maxlength":"","filter":"\\\\Joomla\\\\CMS\\\\Component\\\\ComponentHelper::filterText"}', '', 15, 0),
314+
(0, 'plg_fields_url', 'plugin', 'url', 'fields', 0, 1, 1, 0, 1, '', '', '', 16, 0),
315+
(0, 'plg_fields_user', 'plugin', 'user', 'fields', 0, 1, 1, 0, 1, '', '', '', 17, 0),
316+
(0, 'plg_fields_usergrouplist', 'plugin', 'usergrouplist', 'fields', 0, 1, 1, 0, 1, '', '', '', 18, 0),
316317
(0, 'plg_filesystem_local', 'plugin', 'local', 'filesystem', 0, 1, 1, 0, 1, '', '{}', '', 1, 0),
317318
(0, 'plg_finder_categories', 'plugin', 'categories', 'finder', 0, 1, 1, 0, 1, '', '', '', 1, 0),
318319
(0, 'plg_finder_contacts', 'plugin', 'contacts', 'finder', 0, 1, 1, 0, 1, '', '', '', 2, 0),

plugins/fields/number/number.xml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<extension type="plugin" group="fields" method="upgrade">
3+
<name>plg_fields_number</name>
4+
<author>Joomla! Project</author>
5+
<creationDate>2025-03</creationDate>
6+
<copyright>(C) 2025 Open Source Matters, Inc.</copyright>
7+
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
8+
<authorEmail>[email protected]</authorEmail>
9+
<authorUrl>www.joomla.org</authorUrl>
10+
<version>6.0.0</version>
11+
<description>PLG_FIELDS_NUMBER_XML_DESCRIPTION</description>
12+
<namespace path="src">Joomla\Plugin\Fields\Number</namespace>
13+
<files>
14+
<folder>params</folder>
15+
<folder plugin="number">services</folder>
16+
<folder>src</folder>
17+
<folder>tmpl</folder>
18+
</files>
19+
<languages>
20+
<language tag="en-GB">language/en-GB/plg_fields_number.ini</language>
21+
<language tag="en-GB">language/en-GB/plg_fields_number.sys.ini</language>
22+
</languages>
23+
<config>
24+
<fields name="params">
25+
<fieldset name="basic">
26+
<field
27+
name="min"
28+
type="number"
29+
label="PLG_FIELDS_NUMBER_PARAMS_MIN_LABEL"
30+
description="PLG_FIELDS_NUMBER_PARAMS_MIN_DESC"
31+
default="1.0"
32+
filter="float"
33+
/>
34+
35+
<field
36+
name="max"
37+
type="number"
38+
label="PLG_FIELDS_NUMBER_PARAMS_MAX_LABEL"
39+
description="PLG_FIELDS_NUMBER_PARAMS_MAX_DESC"
40+
default="100.0"
41+
filter="float"
42+
/>
43+
44+
<field
45+
name="step"
46+
type="number"
47+
label="PLG_FIELDS_NUMBER_PARAMS_STEP_LABEL"
48+
default="1.0"
49+
filter="float"
50+
/>
51+
52+
<field
53+
name="currency"
54+
type="radio"
55+
label="PLG_FIELDS_NUMBER_PARAMS_CURRENCY_LABEL"
56+
layout="joomla.form.field.radio.switcher"
57+
default="0"
58+
filter="integer"
59+
>
60+
<option value="0">JNO</option>
61+
<option value="1">JYES</option>
62+
</field>
63+
64+
<field
65+
name="symbol"
66+
type="text"
67+
label="PLG_FIELDS_NUMBER_PARAMS_SYMBOL_LABEL"
68+
filter="string"
69+
showon="currency:1"
70+
/>
71+
72+
<field
73+
name="position"
74+
type="list"
75+
label="PLG_FIELDS_NUMBER_PARAMS_POSITION_LABEL"
76+
default="0"
77+
filter="integer"
78+
showon="currency:1"
79+
>
80+
<option value="0">PLG_FIELDS_NUMBER_PARAMS_POSITION_OPTION_BEFORE</option>
81+
<option value="1">PLG_FIELDS_NUMBER_PARAMS_POSITION_OPTION_AFTER</option>
82+
</field>
83+
84+
<field
85+
name="decimals"
86+
type="int"
87+
label="PLG_FIELDS_NUMBER_PARAMS_DECIMALS_LABEL"
88+
min="0"
89+
max="10"
90+
default="2"
91+
filter="int"
92+
showon="currency:1"
93+
/>
94+
</fieldset>
95+
</fields>
96+
</config>
97+
</extension>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form>
3+
<fields name="fieldparams">
4+
<fieldset name="fieldparams">
5+
<field
6+
name="min"
7+
type="number"
8+
label="PLG_FIELDS_NUMBER_PARAMS_MIN_LABEL"
9+
description="PLG_FIELDS_NUMBER_PARAMS_MIN_DESC"
10+
filter="float"
11+
/>
12+
13+
<field
14+
name="max"
15+
type="number"
16+
label="PLG_FIELDS_NUMBER_PARAMS_MAX_LABEL"
17+
description="PLG_FIELDS_NUMBER_PARAMS_MAX_DESC"
18+
filter="float"
19+
/>
20+
21+
<field
22+
name="step"
23+
type="number"
24+
label="PLG_FIELDS_NUMBER_PARAMS_STEP_LABEL"
25+
default="1.0"
26+
filter="float"
27+
/>
28+
29+
<field
30+
name="currency"
31+
type="radio"
32+
label="PLG_FIELDS_NUMBER_PARAMS_CURRENCY_LABEL"
33+
layout="joomla.form.field.radio.switcher"
34+
default="0"
35+
filter="integer"
36+
>
37+
<option value="0">JNO</option>
38+
<option value="1">JYES</option>
39+
</field>
40+
41+
<field
42+
name="symbol"
43+
type="text"
44+
label="PLG_FIELDS_NUMBER_PARAMS_SYMBOL_LABEL"
45+
filter="string"
46+
showon="currency:1"
47+
/>
48+
49+
<field
50+
name="position"
51+
type="list"
52+
label="PLG_FIELDS_NUMBER_PARAMS_POSITION_LABEL"
53+
default="0"
54+
filter="integer"
55+
showon="currency:1"
56+
>
57+
<option value="0">PLG_FIELDS_NUMBER_PARAMS_POSITION_OPTION_BEFORE</option>
58+
<option value="1">PLG_FIELDS_NUMBER_PARAMS_POSITION_OPTION_AFTER</option>
59+
</field>
60+
61+
<field
62+
name="decimals"
63+
type="int"
64+
label="PLG_FIELDS_NUMBER_PARAMS_DECIMALS_LABEL"
65+
default="2"
66+
filter="integer"
67+
showon="currency:1"
68+
min="0"
69+
max="10"
70+
/>
71+
</fieldset>
72+
</fields>
73+
</form>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/**
4+
* @package Joomla.Plugin
5+
* @subpackage Fields.number
6+
*
7+
* @copyright (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
8+
* @license GNU General Public License version 2 or later; see LICENSE.txt
9+
*/
10+
11+
\defined('_JEXEC') or die;
12+
13+
use Joomla\CMS\Extension\PluginInterface;
14+
use Joomla\CMS\Factory;
15+
use Joomla\CMS\Plugin\PluginHelper;
16+
use Joomla\DI\Container;
17+
use Joomla\DI\ServiceProviderInterface;
18+
use Joomla\Event\DispatcherInterface;
19+
use Joomla\Plugin\Fields\Number\Extension\Number;
20+
21+
return new class () implements ServiceProviderInterface {
22+
/**
23+
* Registers the service provider with a DI container.
24+
*
25+
* @param Container $container The DI container.
26+
*
27+
* @return void
28+
*
29+
* @since __DEPLOY_VERSION__
30+
*/
31+
public function register(Container $container)
32+
{
33+
$container->set(
34+
PluginInterface::class,
35+
function (Container $container) {
36+
$plugin = new Number(
37+
$container->get(DispatcherInterface::class),
38+
(array) PluginHelper::getPlugin('fields', 'number')
39+
);
40+
$plugin->setApplication(Factory::getApplication());
41+
42+
return $plugin;
43+
}
44+
);
45+
}
46+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/**
4+
* @package Joomla.Plugin
5+
* @subpackage Fields.number
6+
*
7+
* @copyright (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
8+
* @license GNU General Public License version 2 or later; see LICENSE.txt
9+
*/
10+
11+
namespace Joomla\Plugin\Fields\Number\Extension;
12+
13+
use Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin;
14+
use Joomla\Event\SubscriberInterface;
15+
16+
// phpcs:disable PSR1.Files.SideEffects
17+
\defined('_JEXEC') or die;
18+
// phpcs:enable PSR1.Files.SideEffects
19+
20+
/**
21+
* Fields Number Plugin
22+
*
23+
* @since __DEPLOY_VERSION__
24+
*/
25+
final class Number extends FieldsPlugin implements SubscriberInterface
26+
{
27+
}

0 commit comments

Comments
 (0)