‪TYPO3CMS  ‪main
PasswordGenerator.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
23 
34 {
35  public function ‪render(): array
36  {
37  $options = $this->data['renderData']['fieldControlOptions'];
38  $itemName = (string)$this->data['parameterArray']['itemFormElName'];
39  $id = ‪StringUtility::getUniqueId('t3js-formengine-fieldcontrol-');
40 
41  // Handle options and fallback
42  $title = $options['title'] ?? 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.generatePassword';
43 
44  $linkAttributes = [
45  'id' => $id,
46  'data-item-name' => $itemName,
47  ];
48 
49  if ($options['allowEdit'] ?? true) {
50  $linkAttributes['data-allow-edit'] = true;
51  }
52 
53  if (is_array($options['passwordRules'] ?? false) && $options['passwordRules'] !== []) {
54  $linkAttributes['data-password-rules'] = (string)json_encode($options['passwordRules'], JSON_THROW_ON_ERROR);
55  }
56 
57  return [
58  'iconIdentifier' => 'actions-dice',
59  'title' => $title,
60  'linkAttributes' => $linkAttributes,
61  'javaScriptModules' => [
62  ‪JavaScriptModuleInstruction::create('@typo3/backend/form-engine/field-control/password-generator.js')->instance($id),
63  ],
64  ];
65  }
66 }
‪TYPO3\CMS\Backend\Form\FieldControl\PasswordGenerator\render
‪render()
Definition: PasswordGenerator.php:35
‪TYPO3\CMS\Backend\Form\FieldControl
Definition: AddRecord.php:18
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction\create
‪static create(string $name, string $exportName=null)
Definition: JavaScriptModuleInstruction.php:47
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction
Definition: JavaScriptModuleInstruction.php:23
‪TYPO3\CMS\Backend\Form\FieldControl\PasswordGenerator
Definition: PasswordGenerator.php:34
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:29
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:24
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static getUniqueId(string $prefix='')
Definition: StringUtility.php:57