From ff5854a3fa4feeb2b0bb09ca515db0b58355ad50 Mon Sep 17 00:00:00 2001
From: Garvin Hicking <gh@faktor-e.de>
Date: Wed, 23 Aug 2023 08:37:14 +0200
Subject: [PATCH] [TASK] Allow passwordGenerator in all TCA types

FormEngine fieldControl "passwordGenerator" can be
handy with TCA type="input" as well.

The patch removes a restriction in PasswordGenerator
that binds this fieldControl exclusively to TCA
type="password".

Resolves: #101703
Related: #98540
Releases: main, 12.4
Change-Id: Ice09e0af2269d5f0aad5afa2d08215d51a04e394
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80653
Tested-by: core-ci <typo3@b13.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
---
 .../Form/FieldControl/PasswordGenerator.php       | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/typo3/sysext/backend/Classes/Form/FieldControl/PasswordGenerator.php b/typo3/sysext/backend/Classes/Form/FieldControl/PasswordGenerator.php
index b6cda4570618..dde51ff63530 100644
--- a/typo3/sysext/backend/Classes/Form/FieldControl/PasswordGenerator.php
+++ b/typo3/sysext/backend/Classes/Form/FieldControl/PasswordGenerator.php
@@ -22,21 +22,20 @@ use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction;
 use TYPO3\CMS\Core\Utility\StringUtility;
 
 /**
- * Renders a widget where a password can be generated, typically used with type=password
+ * Renders a widget to generate a random string in JavaScript.
  *
- * @internal Only to be used by TYPO3. Might change in the future.
+ * This is typically used in combination with TCA type=password as password
+ * generator, but can be potentially used with other field input types as well.
+ *
+ * @internal This is still a bit experimental and may change, for instance to
+ *           be combined with passwordPolicies.
  */
 class PasswordGenerator extends AbstractNode
 {
     public function render(): array
     {
-        $parameterArray = $this->data['parameterArray'];
-        if (($parameterArray['fieldConf']['config']['type'] ?? '') !== 'password') {
-            return [];
-        }
-
         $options = $this->data['renderData']['fieldControlOptions'];
-        $itemName = (string)$parameterArray['itemFormElName'];
+        $itemName = (string)$this->data['parameterArray']['itemFormElName'];
         $id = StringUtility::getUniqueId('t3js-formengine-fieldcontrol-');
 
         // Handle options and fallback
-- 
GitLab