QueuekeyField
QueuekeyField renders the J2Commerce queue secret key alongside a Regenerate button. If no key exists yet, one is generated automatically on first render and persisted to the #__extensions params column. The Regenerate button calls an AJAX endpoint to rotate the key without requiring a full page save.
Class Details
| Property | Value |
|---|---|
| Class | QueuekeyField |
| Namespace | J2Commerce\Component\J2commerce\Administrator\Field |
| File | administrator/components/com_j2commerce/src/Field/QueuekeyField.php |
| Extends | Joomla\CMS\Form\FormField |
| Field type string | Queuekey |
| Since | 6.0.7 |
Behavior
On render the field:
- Reads
queue_keyfromComponentHelper::getParams('com_j2commerce'). - If empty, generates a new key with
md5(sitename . time() . random_bytes(8))and saves it to#__extensionsdirectly. - Displays the key in an
<strong>element inside analert-successbox. - Renders a hidden
<input>holding the current key value. - Emits inline JavaScript that binds a
clicklistener to the Regenerate button.
On click, the JavaScript:
- Disables the button to prevent double-clicks.
- Calls
GET index.php?option=com_j2commerce&task=ajax.regenerateQueuekey&format=jsonwith the CSRF token appended viaJoomla.getOptions('csrf.token'). - On success, updates both the displayed
<strong>text and the hidden<input>value. - Uses
Joomla.renderMessages()for success or error feedback.
AJAX Endpoint
| Property | Value |
|---|---|
| URL | index.php?option=com_j2commerce&task=ajax.regenerateQueuekey&format=json |
| Method | GET |
| Auth | CSRF token passed as query parameter |
| Response | { "success": true, "data": { "queue_key": "..." }, "message": "..." } |
XML Usage
<form addfieldprefix="J2Commerce\Component\J2commerce\Administrator\Field">
<fieldset name="queues">
<field
name="queue_key"
type="Queuekey"
label="COM_J2COMMERCE_QUEUE_KEY_LABEL"
/>
</fieldset>
</form>
XML Attributes
| Attribute | Required | Description |
|---|---|---|
name | Yes | Must be queue_key to bind correctly to the component parameter. |
type | Yes | Must be Queuekey. |
label | Yes | Language key for the field label. |
Output Structure
<div class="alert alert-success d-flex align-items-center gap-3 justify-content-between">
<strong id="j2commerce_queue_key">a3f8c91d...</strong>
<button type="button" class="btn btn-success btn-sm" id="j2commerce_regenerate_queuekey">
Regenerate
</button>
</div>
<input type="hidden" name="jform[queue_key]" id="jform_queue_key" value="a3f8c91d..."/>
<script>/* inline AJAX handler */</script>
Key Generation Algorithm
$queueString = $siteName . time() . bin2hex(random_bytes(8));
$queueKey = md5($queueString);
The key is a 32-character hexadecimal string. It is used in cron URLs to authenticate scheduled task requests.
Usage Notes
- The hidden
<input>carries the key through the standard component config form save. The key is written to#__extensions.paramsas part of the normalcom_configsave flow. - The AJAX regenerate path writes the new key immediately to
#__extensionsand clears theComponentHelperparams cache — no page save is required after clicking Regenerate. - Only one
QueuekeyFieldshould exist in a form at a time. Both element IDs (j2commerce_queue_keyandj2commerce_regenerate_queuekey) are hardcoded.
Related
- CronlasthitField — Displays last cron execution details
- ButtonField — Generic clickable button field