diff --git a/administrator/components/com_admin/sql/updates/mysql/6.0.0-2025-08-17.sql b/administrator/components/com_admin/sql/updates/mysql/6.0.0-2025-08-17.sql new file mode 100644 index 0000000000000..e8b3436b3f2dc --- /dev/null +++ b/administrator/components/com_admin/sql/updates/mysql/6.0.0-2025-08-17.sql @@ -0,0 +1,2 @@ +INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `locked`, `manifest_cache`, `params`, `custom_data`, `ordering`, `state`) VALUES +(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); diff --git a/administrator/components/com_admin/sql/updates/postgresql/6.0.0-2025-08-17.sql b/administrator/components/com_admin/sql/updates/postgresql/6.0.0-2025-08-17.sql new file mode 100644 index 0000000000000..e744872eda786 --- /dev/null +++ b/administrator/components/com_admin/sql/updates/postgresql/6.0.0-2025-08-17.sql @@ -0,0 +1,2 @@ +INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "locked", "manifest_cache", "params", "custom_data", "ordering", "state") VALUES +(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); diff --git a/administrator/language/en-GB/plg_fields_number.ini b/administrator/language/en-GB/plg_fields_number.ini new file mode 100644 index 0000000000000..5d8e95d46a19c --- /dev/null +++ b/administrator/language/en-GB/plg_fields_number.ini @@ -0,0 +1,19 @@ +; Joomla! Project +; (C) 2025 Open Source Matters, Inc. +; License GNU General Public License version 2 or later; see LICENSE.txt +; Note : All ini files need to be saved as UTF-8 + +PLG_FIELDS_NUMBER="Fields - Number" +PLG_FIELDS_NUMBER_LABEL="Number (%s)" +PLG_FIELDS_NUMBER_PARAMS_CURRENCY_LABEL="Format as Currency" +PLG_FIELDS_NUMBER_PARAMS_DECIMALS_LABEL="Number of Decimals" +PLG_FIELDS_NUMBER_PARAMS_MAX_DESC="Maximum value that can be chosen (only limits the up/down arrows)." +PLG_FIELDS_NUMBER_PARAMS_MAX_LABEL="Maximum" +PLG_FIELDS_NUMBER_PARAMS_MIN_DESC="Minimum value that can be chosen (only limits the up/down arrows)." +PLG_FIELDS_NUMBER_PARAMS_MIN_LABEL="Minimum" +PLG_FIELDS_NUMBER_PARAMS_POSITION_LABEL="Symbol Position" +PLG_FIELDS_NUMBER_PARAMS_POSITION_OPTION_AFTER="After" +PLG_FIELDS_NUMBER_PARAMS_POSITION_OPTION_BEFORE="Before" +PLG_FIELDS_NUMBER_PARAMS_STEP_LABEL="Step Increment" +PLG_FIELDS_NUMBER_PARAMS_SYMBOL_LABEL="Currency Symbol" +PLG_FIELDS_NUMBER_XML_DESCRIPTION="This plugin lets you create new fields of type 'number' in any extensions where custom fields are supported." diff --git a/administrator/language/en-GB/plg_fields_number.sys.ini b/administrator/language/en-GB/plg_fields_number.sys.ini new file mode 100644 index 0000000000000..fb94567cd845e --- /dev/null +++ b/administrator/language/en-GB/plg_fields_number.sys.ini @@ -0,0 +1,7 @@ +; Joomla! Project +; (C) 2025 Open Source Matters, Inc. +; License GNU General Public License version 2 or later; see LICENSE.txt +; Note : All ini files need to be saved as UTF-8 + +PLG_FIELDS_NUMBER="Fields - Number" +PLG_FIELDS_NUMBER_XML_DESCRIPTION="This plugin lets you create new fields of type 'number' in any extensions where custom fields are supported." diff --git a/installation/sql/mysql/base.sql b/installation/sql/mysql/base.sql index f660558281f97..58c637c09c339 100644 --- a/installation/sql/mysql/base.sql +++ b/installation/sql/mysql/base.sql @@ -299,14 +299,15 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, (0, 'plg_fields_list', 'plugin', 'list', 'fields', 0, 1, 1, 0, 1, '', '', '', 7, 0), (0, 'plg_fields_media', 'plugin', 'media', 'fields', 0, 1, 1, 0, 1, '', '', '', 8, 0), (0, 'plg_fields_note', 'plugin', 'note', 'fields', 0, 1, 1, 0, 1, '', '{"class":"alert alert-info","heading":"h4"}', '', 9, 0), -(0, 'plg_fields_radio', 'plugin', 'radio', 'fields', 0, 1, 1, 0, 1, '', '', '', 10, 0), -(0, 'plg_fields_sql', 'plugin', 'sql', 'fields', 0, 1, 1, 0, 1, '', '', '', 11, 0), -(0, 'plg_fields_subform', 'plugin', 'subform', 'fields', 0, 1, 1, 0, 1, '', '', '', 12, 0), -(0, 'plg_fields_text', 'plugin', 'text', 'fields', 0, 1, 1, 0, 1, '', '', '', 13, 0), -(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), -(0, 'plg_fields_url', 'plugin', 'url', 'fields', 0, 1, 1, 0, 1, '', '', '', 15, 0), -(0, 'plg_fields_user', 'plugin', 'user', 'fields', 0, 1, 1, 0, 1, '', '', '', 16, 0), -(0, 'plg_fields_usergrouplist', 'plugin', 'usergrouplist', 'fields', 0, 1, 1, 0, 1, '', '', '', 17, 0), +(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), +(0, 'plg_fields_radio', 'plugin', 'radio', 'fields', 0, 1, 1, 0, 1, '', '', '', 11, 0), +(0, 'plg_fields_sql', 'plugin', 'sql', 'fields', 0, 1, 1, 0, 1, '', '', '', 12, 0), +(0, 'plg_fields_subform', 'plugin', 'subform', 'fields', 0, 1, 1, 0, 1, '', '', '', 13, 0), +(0, 'plg_fields_text', 'plugin', 'text', 'fields', 0, 1, 1, 0, 1, '', '', '', 14, 0), +(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), +(0, 'plg_fields_url', 'plugin', 'url', 'fields', 0, 1, 1, 0, 1, '', '', '', 16, 0), +(0, 'plg_fields_user', 'plugin', 'user', 'fields', 0, 1, 1, 0, 1, '', '', '', 17, 0), +(0, 'plg_fields_usergrouplist', 'plugin', 'usergrouplist', 'fields', 0, 1, 1, 0, 1, '', '', '', 18, 0), (0, 'plg_filesystem_local', 'plugin', 'local', 'filesystem', 0, 1, 1, 0, 1, '', '{}', '', 1, 0), (0, 'plg_finder_categories', 'plugin', 'categories', 'finder', 0, 1, 1, 0, 1, '', '', '', 1, 0), (0, 'plg_finder_contacts', 'plugin', 'contacts', 'finder', 0, 1, 1, 0, 1, '', '', '', 2, 0), diff --git a/installation/sql/postgresql/base.sql b/installation/sql/postgresql/base.sql index 038c213cc59ba..07853d67681b1 100644 --- a/installation/sql/postgresql/base.sql +++ b/installation/sql/postgresql/base.sql @@ -305,14 +305,15 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", (0, 'plg_fields_list', 'plugin', 'list', 'fields', 0, 1, 1, 0, 1, '', '', '', 7, 0), (0, 'plg_fields_media', 'plugin', 'media', 'fields', 0, 1, 1, 0, 1, '', '', '', 8, 0), (0, 'plg_fields_note', 'plugin', 'note', 'fields', 0, 1, 1, 0, 1, '', '{"class":"alert alert-info","heading":"h4"}', '', 9, 0), -(0, 'plg_fields_radio', 'plugin', 'radio', 'fields', 0, 1, 1, 0, 1, '', '', '', 10, 0), -(0, 'plg_fields_sql', 'plugin', 'sql', 'fields', 0, 1, 1, 0, 1, '', '', '', 11, 0), -(0, 'plg_fields_subform', 'plugin', 'subform', 'fields', 0, 1, 1, 0, 1, '', '', '', 12, 0), -(0, 'plg_fields_text', 'plugin', 'text', 'fields', 0, 1, 1, 0, 1, '', '', '', 13, 0), -(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), -(0, 'plg_fields_url', 'plugin', 'url', 'fields', 0, 1, 1, 0, 1, '', '', '', 15, 0), -(0, 'plg_fields_user', 'plugin', 'user', 'fields', 0, 1, 1, 0, 1, '', '', '', 16, 0), -(0, 'plg_fields_usergrouplist', 'plugin', 'usergrouplist', 'fields', 0, 1, 1, 0, 1, '', '', '', 17, 0), +(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), +(0, 'plg_fields_radio', 'plugin', 'radio', 'fields', 0, 1, 1, 0, 1, '', '', '', 11, 0), +(0, 'plg_fields_sql', 'plugin', 'sql', 'fields', 0, 1, 1, 0, 1, '', '', '', 12, 0), +(0, 'plg_fields_subform', 'plugin', 'subform', 'fields', 0, 1, 1, 0, 1, '', '', '', 13, 0), +(0, 'plg_fields_text', 'plugin', 'text', 'fields', 0, 1, 1, 0, 1, '', '', '', 14, 0), +(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), +(0, 'plg_fields_url', 'plugin', 'url', 'fields', 0, 1, 1, 0, 1, '', '', '', 16, 0), +(0, 'plg_fields_user', 'plugin', 'user', 'fields', 0, 1, 1, 0, 1, '', '', '', 17, 0), +(0, 'plg_fields_usergrouplist', 'plugin', 'usergrouplist', 'fields', 0, 1, 1, 0, 1, '', '', '', 18, 0), (0, 'plg_filesystem_local', 'plugin', 'local', 'filesystem', 0, 1, 1, 0, 1, '', '{}', '', 1, 0), (0, 'plg_finder_categories', 'plugin', 'categories', 'finder', 0, 1, 1, 0, 1, '', '', '', 1, 0), (0, 'plg_finder_contacts', 'plugin', 'contacts', 'finder', 0, 1, 1, 0, 1, '', '', '', 2, 0), diff --git a/plugins/fields/number/number.xml b/plugins/fields/number/number.xml new file mode 100644 index 0000000000000..bc4cb8b92679e --- /dev/null +++ b/plugins/fields/number/number.xml @@ -0,0 +1,97 @@ + + + plg_fields_number + Joomla! Project + 2025-03 + (C) 2025 Open Source Matters, Inc. + GNU General Public License version 2 or later; see LICENSE.txt + admin@joomla.org + www.joomla.org + 6.0.0 + PLG_FIELDS_NUMBER_XML_DESCRIPTION + Joomla\Plugin\Fields\Number + + params + services + src + tmpl + + + language/en-GB/plg_fields_number.ini + language/en-GB/plg_fields_number.sys.ini + + + +
+ + + + + + + + + + + + + + + + + + + +
+
+
+
diff --git a/plugins/fields/number/params/number.xml b/plugins/fields/number/params/number.xml new file mode 100644 index 0000000000000..4ef945085f5eb --- /dev/null +++ b/plugins/fields/number/params/number.xml @@ -0,0 +1,73 @@ + +
+ +
+ + + + + + + + + + + + + + + + + + + +
+
+
diff --git a/plugins/fields/number/services/provider.php b/plugins/fields/number/services/provider.php new file mode 100644 index 0000000000000..83621e76ce50a --- /dev/null +++ b/plugins/fields/number/services/provider.php @@ -0,0 +1,46 @@ + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +\defined('_JEXEC') or die; + +use Joomla\CMS\Extension\PluginInterface; +use Joomla\CMS\Factory; +use Joomla\CMS\Plugin\PluginHelper; +use Joomla\DI\Container; +use Joomla\DI\ServiceProviderInterface; +use Joomla\Event\DispatcherInterface; +use Joomla\Plugin\Fields\Number\Extension\Number; + +return new class () implements ServiceProviderInterface { + /** + * Registers the service provider with a DI container. + * + * @param Container $container The DI container. + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + public function register(Container $container) + { + $container->set( + PluginInterface::class, + function (Container $container) { + $plugin = new Number( + $container->get(DispatcherInterface::class), + (array) PluginHelper::getPlugin('fields', 'number') + ); + $plugin->setApplication(Factory::getApplication()); + + return $plugin; + } + ); + } +}; diff --git a/plugins/fields/number/src/Extension/Number.php b/plugins/fields/number/src/Extension/Number.php new file mode 100644 index 0000000000000..9e3ad2e36a669 --- /dev/null +++ b/plugins/fields/number/src/Extension/Number.php @@ -0,0 +1,27 @@ + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace Joomla\Plugin\Fields\Number\Extension; + +use Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin; +use Joomla\Event\SubscriberInterface; + +// phpcs:disable PSR1.Files.SideEffects +\defined('_JEXEC') or die; +// phpcs:enable PSR1.Files.SideEffects + +/** + * Fields Number Plugin + * + * @since __DEPLOY_VERSION__ + */ +final class Number extends FieldsPlugin implements SubscriberInterface +{ +} diff --git a/plugins/fields/number/tmpl/number.php b/plugins/fields/number/tmpl/number.php new file mode 100644 index 0000000000000..257cd1bfd91e5 --- /dev/null +++ b/plugins/fields/number/tmpl/number.php @@ -0,0 +1,32 @@ + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +defined('_JEXEC') or die; + +use Joomla\CMS\Language\Text; + +$value = $field->value; +$min = $field->fieldparams->get('min', null); +$currency = $field->fieldparams->get('currency', 0); +$decimals = $field->fieldparams->get('decimals', 2); +$symbol = $field->fieldparams->get('symbol', 2); +$position = $field->fieldparams->get('position', 2); + +if (is_numeric($value)) { + $value = (float)$value; + if ($currency) { + $formattedCurrency = number_format($value, $decimals, Text::_('DECIMALS_SEPARATOR'), Text::_('THOUSANDS_SEPARATOR')); + $value = $position ? ($formattedCurrency . $symbol) : ($symbol . $formattedCurrency) ; + } +} else { + $value = $min ?? ''; +} + +echo $value;