first commit
This commit is contained in:
51
plugins/fields/checkboxes/checkboxes.xml
Normal file
51
plugins/fields/checkboxes/checkboxes.xml
Normal file
@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extension type="plugin" group="fields" method="upgrade">
|
||||
<name>plg_fields_checkboxes</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>2016-03</creationDate>
|
||||
<copyright>(C) 2016 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>3.7.0</version>
|
||||
<description>PLG_FIELDS_CHECKBOXES_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Plugin\Fields\Checkboxes</namespace>
|
||||
<files>
|
||||
<folder>params</folder>
|
||||
<folder plugin="checkboxes">services</folder>
|
||||
<folder>src</folder>
|
||||
<folder>tmpl</folder>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">language/en-GB/plg_fields_checkboxes.ini</language>
|
||||
<language tag="en-GB">language/en-GB/plg_fields_checkboxes.sys.ini</language>
|
||||
</languages>
|
||||
<config>
|
||||
<fields name="params">
|
||||
<fieldset name="basic">
|
||||
<field
|
||||
name="options"
|
||||
type="subform"
|
||||
label="PLG_FIELDS_CHECKBOXES_PARAMS_OPTIONS_LABEL"
|
||||
layout="joomla.form.field.subform.repeatable-table"
|
||||
icon="list"
|
||||
multiple="true"
|
||||
>
|
||||
<form hidden="true" name="list_templates_modal" repeat="true">
|
||||
<field
|
||||
name="name"
|
||||
type="text"
|
||||
label="PLG_FIELDS_CHECKBOXES_PARAMS_OPTIONS_NAME_LABEL"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="value"
|
||||
type="text"
|
||||
label="PLG_FIELDS_CHECKBOXES_PARAMS_OPTIONS_VALUE_LABEL"
|
||||
/>
|
||||
</form>
|
||||
</field>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</config>
|
||||
</extension>
|
||||
30
plugins/fields/checkboxes/params/checkboxes.xml
Normal file
30
plugins/fields/checkboxes/params/checkboxes.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form>
|
||||
<fields name="fieldparams">
|
||||
<fieldset name="fieldparams">
|
||||
<field
|
||||
name="options"
|
||||
type="subform"
|
||||
label="PLG_FIELDS_CHECKBOXES_PARAMS_OPTIONS_LABEL"
|
||||
layout="joomla.form.field.subform.repeatable-table"
|
||||
icon="list"
|
||||
multiple="true"
|
||||
>
|
||||
<form hidden="true" name="list_templates_modal" repeat="true">
|
||||
<field
|
||||
name="name"
|
||||
type="text"
|
||||
label="PLG_FIELDS_CHECKBOXES_PARAMS_OPTIONS_NAME_LABEL"
|
||||
required="true"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="value"
|
||||
type="text"
|
||||
label="PLG_FIELDS_CHECKBOXES_PARAMS_OPTIONS_VALUE_LABEL"
|
||||
/>
|
||||
</form>
|
||||
</field>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</form>
|
||||
46
plugins/fields/checkboxes/services/provider.php
Normal file
46
plugins/fields/checkboxes/services/provider.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Fields.checkboxes
|
||||
*
|
||||
* @copyright (C) 2023 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\Event\DispatcherInterface;
|
||||
use Joomla\Plugin\Fields\Checkboxes\Extension\Checkboxes;
|
||||
|
||||
return new class () implements ServiceProviderInterface {
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.3.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->set(
|
||||
PluginInterface::class,
|
||||
function (Container $container) {
|
||||
$plugin = new Checkboxes(
|
||||
$container->get(DispatcherInterface::class),
|
||||
(array) PluginHelper::getPlugin('fields', 'checkboxes')
|
||||
);
|
||||
$plugin->setApplication(Factory::getApplication());
|
||||
|
||||
return $plugin;
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
63
plugins/fields/checkboxes/src/Extension/Checkboxes.php
Normal file
63
plugins/fields/checkboxes/src/Extension/Checkboxes.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Fields.checkboxes
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Plugin\Fields\Checkboxes\Extension;
|
||||
|
||||
use Joomla\Component\Fields\Administrator\Plugin\FieldsListPlugin;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Fields Checkboxes Plugin
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
final class Checkboxes extends FieldsListPlugin
|
||||
{
|
||||
/**
|
||||
* Before prepares the field value.
|
||||
*
|
||||
* @param string $context The context.
|
||||
* @param \stdclass $item The item.
|
||||
* @param \stdclass $field The field.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
public function onCustomFieldsBeforePrepareField($context, $item, $field)
|
||||
{
|
||||
if (!$this->getApplication()->isClient('api')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->isTypeSupported($field->type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$field->apivalue = [];
|
||||
|
||||
$options = $this->getOptionsFromField($field);
|
||||
|
||||
if (empty($field->value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (\is_array($field->value)) {
|
||||
foreach ($field->value as $key => $value) {
|
||||
$field->apivalue[$value] = $options[$value];
|
||||
}
|
||||
} else {
|
||||
$field->apivalue[$field->value] = $options[$field->value];
|
||||
}
|
||||
}
|
||||
}
|
||||
31
plugins/fields/checkboxes/tmpl/checkboxes.php
Normal file
31
plugins/fields/checkboxes/tmpl/checkboxes.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Fields.Checkboxes
|
||||
*
|
||||
* @copyright (C) 2017 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;
|
||||
|
||||
$fieldValue = $field->value;
|
||||
|
||||
if ($fieldValue === '' || $fieldValue === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fieldValue = (array) $fieldValue;
|
||||
$texts = [];
|
||||
$options = $this->getOptionsFromField($field);
|
||||
|
||||
foreach ($options as $value => $name) {
|
||||
if (in_array((string) $value, $fieldValue)) {
|
||||
$texts[] = Text::_($name);
|
||||
}
|
||||
}
|
||||
|
||||
echo htmlentities(implode(', ', $texts));
|
||||
Reference in New Issue
Block a user