init
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extension type="plugin" group="fields" method="upgrade">
|
||||
<name>plg_fields_number</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>2025-03</creationDate>
|
||||
<copyright>(C) 2025 Open Source Matters, Inc.</copyright>
|
||||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
||||
<authorEmail>admin@joomla.org</authorEmail>
|
||||
<authorUrl>www.joomla.org</authorUrl>
|
||||
<version>6.0.0</version>
|
||||
<description>PLG_FIELDS_NUMBER_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Plugin\Fields\Number</namespace>
|
||||
<files>
|
||||
<folder>params</folder>
|
||||
<folder plugin="number">services</folder>
|
||||
<folder>src</folder>
|
||||
<folder>tmpl</folder>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">language/en-GB/plg_fields_number.ini</language>
|
||||
<language tag="en-GB">language/en-GB/plg_fields_number.sys.ini</language>
|
||||
</languages>
|
||||
<config>
|
||||
<fields name="params">
|
||||
<fieldset name="basic">
|
||||
<field
|
||||
name="min"
|
||||
type="number"
|
||||
label="PLG_FIELDS_NUMBER_PARAMS_MIN_LABEL"
|
||||
description="PLG_FIELDS_NUMBER_PARAMS_MIN_DESC"
|
||||
default="1.0"
|
||||
filter="float"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="max"
|
||||
type="number"
|
||||
label="PLG_FIELDS_NUMBER_PARAMS_MAX_LABEL"
|
||||
description="PLG_FIELDS_NUMBER_PARAMS_MAX_DESC"
|
||||
default="100.0"
|
||||
filter="float"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="step"
|
||||
type="number"
|
||||
label="PLG_FIELDS_NUMBER_PARAMS_STEP_LABEL"
|
||||
default="1.0"
|
||||
filter="float"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="currency"
|
||||
type="radio"
|
||||
label="PLG_FIELDS_NUMBER_PARAMS_CURRENCY_LABEL"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
default="0"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="symbol"
|
||||
type="text"
|
||||
label="PLG_FIELDS_NUMBER_PARAMS_SYMBOL_LABEL"
|
||||
filter="string"
|
||||
showon="currency:1"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="position"
|
||||
type="list"
|
||||
label="PLG_FIELDS_NUMBER_PARAMS_POSITION_LABEL"
|
||||
default="0"
|
||||
filter="integer"
|
||||
showon="currency:1"
|
||||
>
|
||||
<option value="0">PLG_FIELDS_NUMBER_PARAMS_POSITION_OPTION_BEFORE</option>
|
||||
<option value="1">PLG_FIELDS_NUMBER_PARAMS_POSITION_OPTION_AFTER</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="decimals"
|
||||
type="int"
|
||||
label="PLG_FIELDS_NUMBER_PARAMS_DECIMALS_LABEL"
|
||||
min="0"
|
||||
max="10"
|
||||
default="2"
|
||||
filter="int"
|
||||
showon="currency:1"
|
||||
/>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</config>
|
||||
</extension>
|
||||
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form>
|
||||
<fields name="fieldparams">
|
||||
<fieldset name="fieldparams">
|
||||
<field
|
||||
name="min"
|
||||
type="number"
|
||||
label="PLG_FIELDS_NUMBER_PARAMS_MIN_LABEL"
|
||||
description="PLG_FIELDS_NUMBER_PARAMS_MIN_DESC"
|
||||
filter="float"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="max"
|
||||
type="number"
|
||||
label="PLG_FIELDS_NUMBER_PARAMS_MAX_LABEL"
|
||||
description="PLG_FIELDS_NUMBER_PARAMS_MAX_DESC"
|
||||
filter="float"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="step"
|
||||
type="number"
|
||||
label="PLG_FIELDS_NUMBER_PARAMS_STEP_LABEL"
|
||||
default="1.0"
|
||||
filter="float"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="currency"
|
||||
type="radio"
|
||||
label="PLG_FIELDS_NUMBER_PARAMS_CURRENCY_LABEL"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
default="0"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="symbol"
|
||||
type="text"
|
||||
label="PLG_FIELDS_NUMBER_PARAMS_SYMBOL_LABEL"
|
||||
filter="string"
|
||||
showon="currency:1"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="position"
|
||||
type="list"
|
||||
label="PLG_FIELDS_NUMBER_PARAMS_POSITION_LABEL"
|
||||
default="0"
|
||||
filter="integer"
|
||||
showon="currency:1"
|
||||
>
|
||||
<option value="0">PLG_FIELDS_NUMBER_PARAMS_POSITION_OPTION_BEFORE</option>
|
||||
<option value="1">PLG_FIELDS_NUMBER_PARAMS_POSITION_OPTION_AFTER</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="decimals"
|
||||
type="int"
|
||||
label="PLG_FIELDS_NUMBER_PARAMS_DECIMALS_LABEL"
|
||||
default="2"
|
||||
filter="integer"
|
||||
showon="currency:1"
|
||||
min="0"
|
||||
max="10"
|
||||
/>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</form>
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Fields.number
|
||||
*
|
||||
* @copyright (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @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\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 6.0.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->set(
|
||||
PluginInterface::class,
|
||||
$container->lazy(Number::class, function (Container $container) {
|
||||
$plugin = new Number(
|
||||
(array) PluginHelper::getPlugin('fields', 'number')
|
||||
);
|
||||
$plugin->setApplication(Factory::getApplication());
|
||||
|
||||
return $plugin;
|
||||
})
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Fields.number
|
||||
*
|
||||
* @copyright (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @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 6.0.0
|
||||
*/
|
||||
final class Number extends FieldsPlugin implements SubscriberInterface
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Fields.Number
|
||||
*
|
||||
* @copyright (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @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', '');
|
||||
$position = $field->fieldparams->get('position', 0);
|
||||
|
||||
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;
|
||||
Reference in New Issue
Block a user