Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature #184271 feat: Unique ID generation field #358

Open
wants to merge 1 commit into
base: release-2.0.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions admin_language/en-GB/en-GB.com_tjfields.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions administrator/models/fields/tjfieldfields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
64 changes: 64 additions & 0 deletions administrator/models/fields/uniqueid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* @package Tjfields
* @author Techjoomla <[email protected]>
* @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[] = '<input type="hidden" name="' . $this->name . '" value="'. $uniqueidValue.'" readonly />';
}

return implode($html);
}
}
5 changes: 5 additions & 0 deletions site/helpers/tjfields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down