diff --git a/admin_language/en-GB/en-GB.com_tjfields.ini b/admin_language/en-GB/en-GB.com_tjfields.ini index a859cf27..fecf571d 100755 --- a/admin_language/en-GB/en-GB.com_tjfields.ini +++ b/admin_language/en-GB/en-GB.com_tjfields.ini @@ -554,3 +554,6 @@ COM_TJFIELDS_FORM_LBL_ITEM_CATEGORY_FIELD_STATE="State" COM_TJFIELDS_FORM_DESC_ITEM_CATEGORY_FIELD_STATE="(1/0/2/-2) is whether the drop down will show only published (1), unpublished (0), archived (2) or trashed (-2) categories. It is possible to combine different publishing status by entering the list of the corresponding numbers separated by comma (e.g. "0,2,-2" will display only unpublished, archived and trashed categories in the drop-down)" COM_TJFIELDS_CAPTURE_IMAGE="Capture Image" COM_TJFIELDS_LBL_ACCORDION="Accordion Tag" + +;Added in 2.0.2 +COM_TJFIELDS_UNIQUEID="UniqueId" diff --git a/administrator/models/fields/tjfieldfields.php b/administrator/models/fields/tjfieldfields.php index 9f8b5e79..087add61 100644 --- a/administrator/models/fields/tjfieldfields.php +++ b/administrator/models/fields/tjfieldfields.php @@ -82,6 +82,7 @@ protected function getInput() $options[] = HTMLHelper::_('select.option', 'itemcategory', Text::_('COM_TJFIELDS_ITEM_CATEGORY')); $options[] = HTMLHelper::_('select.option', 'number', Text::_('COM_TJFIELDS_NUMBER')); $options[] = HTMLHelper::_('select.option', 'hidden', Text::_('COM_TJFIELDS_HIDDEN')); + $options[] = HTMLHelper::_('select.option', 'uniqueid', Text::_('COM_TJFIELDS_UNIQUEID')); if ($installUcm === 1) { diff --git a/administrator/models/fields/uniqueid.php b/administrator/models/fields/uniqueid.php new file mode 100644 index 00000000..85bdb0b2 --- /dev/null +++ b/administrator/models/fields/uniqueid.php @@ -0,0 +1,64 @@ + + * @copyright Copyright (c) 2009-2022 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ + +defined('JPATH_BASE') or die; + +use Joomla\CMS\Factory; +use Joomla\CMS\Form\FormField; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; + +/** + * Supports an HTML select list of categories + * + * @since 1.0 + */ +class JFormFieldUniqueid extends FormField +{ + /** + * The form field type. + * + * @var string + * @since 1.0 + */ + protected $type = 'uniqueid'; + + /** + * Method to get the field input markup. + * + * @return string The field input markup. + * + * @since 1.6 + */ + protected function getInput() + { + $html = array(); + $input = Factory::getApplication()->input; + $ucmId = $input->get("id", 0, "INT"); + + if (empty($this->value)) + { + $characters = '0123456789'; + $charactersLength = strlen($characters); + $randomString = ''; + + for ($i = 0; $i < $this->element->attributes()->uniqueid_digitcount; $i++) + { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + + $uniqueidValue = $this->element->attributes()->uniqueid_prefix . '_' . $randomString . '_'; + } + + if (!empty($uniqueidValue)) + { + $html[] = ''; + } + + return implode($html); + } +} diff --git a/site/helpers/tjfields.php b/site/helpers/tjfields.php index 79cfdad1..96729625 100644 --- a/site/helpers/tjfields.php +++ b/site/helpers/tjfields.php @@ -250,6 +250,11 @@ public function saveFieldsValue($data) { $this->saveMediaFieldData($fieldValue, $field->client, $data['content_id'], $field->id, $fieldStoredValues); } + elseif ($field->type == 'uniqueid') + { + $fieldValue = $fieldValue . $data['content_id']; + $this->saveSingleValuedFieldData($fieldValue, $field->client, $data['content_id'], $field->id, $fieldStoredValues); + } elseif ($field->type == 'subform') { $fieldValue = json_encode($fieldValue);