TYPO3 v15 dev-main snapshot ()

This commit is contained in:
2026-08-10 22:31:00 +02:00
commit f9941541b7
1178 changed files with 135377 additions and 0 deletions
+131
View File
@@ -0,0 +1,131 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Backend\Form\FieldControl;
use TYPO3\CMS\Backend\Form\AbstractNode;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
/**
* Renders the icon with link parameters to add a new record,
* typically used for single elements of type=group or type=select.
*/
class AddRecord extends AbstractNode
{
public function __construct(
private readonly UriBuilder $uriBuilder,
) {}
/**
* Add button control
*
* @return array As defined by FieldControl class
*/
public function render(): array
{
$options = $this->data['renderData']['fieldControlOptions'];
$parameterArray = $this->data['parameterArray'];
$itemName = (string)$parameterArray['itemFormElName'];
// Handle options and fallback
$title = $options['title'] ?? 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.createNew';
$setValue = $options['setValue'] ?? 'append';
$table = '';
if (isset($options['table'])) {
// Table given in options - use it
$table = $options['table'];
} elseif ($parameterArray['fieldConf']['config']['type'] === 'group'
&& !empty($parameterArray['fieldConf']['config']['allowed'])
) {
// Use first table from allowed list if specific table is not set in options
$allowedTables = GeneralUtility::trimExplode(',', $parameterArray['fieldConf']['config']['allowed'], true);
$table = array_pop($allowedTables);
} elseif ($parameterArray['fieldConf']['config']['type'] === 'select'
&& !empty($parameterArray['fieldConf']['config']['foreign_table'])
) {
// Use foreign_table if given for type=select
$table = $parameterArray['fieldConf']['config']['foreign_table'];
}
if (empty($table)) {
// Still no table - this element can not handle the add control.
return [];
}
$prefixOfFormElName = 'data[' . $this->data['tableName'] . '][' . $this->data['databaseRow']['uid'] . '][' . $this->data['fieldName'] . ']';
$flexFormPath = '';
if (str_starts_with($itemName, $prefixOfFormElName)) {
$flexFormPath = str_replace('][', '/', substr($itemName, strlen($prefixOfFormElName) + 1, -1));
}
$urlParameters = [
'P' => [
'params' => [
'table' => $table,
'pid' => $this->resolvePid($options, $table),
'setValue' => $setValue,
],
'table' => $this->data['tableName'],
'field' => $this->data['fieldName'],
'uid' => $this->data['databaseRow']['uid'],
'flexFormPath' => $flexFormPath,
'returnUrl' => $this->data['returnUrl'],
],
];
$id = StringUtility::getUniqueId('t3js-formengine-fieldcontrol-');
return [
'iconIdentifier' => 'actions-plus',
'title' => $title,
'linkAttributes' => [
'id' => $id,
'href' => (string)$this->uriBuilder->buildUriFromRoute('wizard_add', $urlParameters),
],
'javaScriptModules' => [
JavaScriptModuleInstruction::create('@typo3/backend/form-engine/field-control/add-record.js')->instance('#' . $id),
],
];
}
protected function resolvePid(array $options, string $table): string
{
// Target pid of new records is current pid by default
$pid = $this->data['effectivePid'];
if (isset($options['pid'])) {
// pid configured in options - use it
if ($options['pid'] === '###SITEROOT###' && ($this->data['site'] ?? null) instanceof Site) {
// Substitute marker with pid from site object
$pid = $this->data['site']->getRootPageId();
} else {
// This might be a static pid or a marker such as ###PAGE_TSCONFIG_ID###
$pid = $options['pid'];
}
} elseif (
$this->data['tcaSchemata']->has($table)
&& (int)($this->data['tcaSchemata']->get($table)->getRawConfiguration()['rootLevel'] ?? 0) === 1
) {
// Target table can only exist on root level - set 0 as pid
$pid = 0;
}
return (string)$pid;
}
}
+107
View File
@@ -0,0 +1,107 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Backend\Form\FieldControl;
use TYPO3\CMS\Backend\Form\AbstractNode;
use TYPO3\CMS\Backend\Form\Behavior\OnFieldChangeTrait;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Crypto\HashService;
use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction;
use TYPO3\CMS\Core\Utility\StringUtility;
/**
* Renders the icon with link parameters to edit a selected element,
* typically used for single elements of type=group or type=select.
*/
class EditPopup extends AbstractNode
{
use OnFieldChangeTrait;
public function __construct(
private readonly UriBuilder $uriBuilder,
private readonly HashService $hashService,
) {}
/**
* Edit popup control
*
* @return array As defined by FieldControl class
*/
public function render(): array
{
$options = $this->data['renderData']['fieldControlOptions'];
$title = $options['title'] ?? 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.edit';
$parameterArray = $this->data['parameterArray'];
$itemName = $parameterArray['itemFormElName'];
$windowOpenParameters = $options['windowOpenParameters'] ?? 'height=800,width=900,status=0,menubar=0,scrollbars=1';
$flexFormDataStructureIdentifier = $this->data['flexFormDataStructureIdentifier'] ?? '';
$flexFormDataStructurePath = '';
if (!empty($flexFormDataStructureIdentifier)) {
if (empty($this->data['flexFormContainerName'])) {
// simple flex form element
$flexFormDataStructurePath = 'sheets/'
. $this->data['flexFormSheetName']
. '/ROOT/el/'
. $this->data['flexFormFieldName']
. '/config';
} else {
// flex form section container element
$flexFormDataStructurePath = 'sheets/'
. $this->data['flexFormSheetName']
. '/ROOT/el/'
. $this->data['flexFormFieldName']
. '/el/'
. $this->data['flexFormContainerName']
. '/el/'
. $this->data['flexFormContainerFieldName']
. '/config';
}
}
$urlParameters = array_merge(
[
'table' => $this->data['tableName'],
'field' => $this->data['fieldName'],
'formName' => 'editform',
'flexFormDataStructureIdentifier' => $flexFormDataStructureIdentifier,
'flexFormDataStructurePath' => $flexFormDataStructurePath,
'hmac' => $this->hashService->hmac('editform' . $itemName, 'wizard_js'),
],
$this->forwardOnFieldChangeQueryParams($parameterArray['fieldChangeFunc'] ?? [])
);
$url = (string)$this->uriBuilder->buildUriFromRoute('wizard_edit', ['P' => $urlParameters]);
$id = StringUtility::getUniqueId('t3js-formengine-fieldcontrol-');
return [
'iconIdentifier' => 'actions-open',
'title' => $title,
'linkAttributes' => [
'id' => $id,
'href' => $url,
'data-element' => $itemName,
'data-window-parameters' => $windowOpenParameters,
],
'javaScriptModules' => [
JavaScriptModuleInstruction::create('@typo3/backend/form-engine/field-control/edit-popup.js')->instance('#' . $id),
],
];
}
}
@@ -0,0 +1,171 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Backend\Form\FieldControl;
use TYPO3\CMS\Backend\Form\AbstractNode;
use TYPO3\CMS\Backend\Form\InlineStackProcessor;
use TYPO3\CMS\Backend\Form\Utility\FormEngineUtility;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Renders the icon "select element via element browser",
* typically used for type=group.
*/
class ElementBrowser extends AbstractNode
{
public function __construct(
private readonly InlineStackProcessor $inlineStackProcessor,
) {}
/**
* Add button control
*
* @return array As defined by FieldControl class
*/
public function render(): array
{
$table = $this->data['tableName'];
$fieldName = $this->data['fieldName'];
$options = $this->data['renderData']['fieldControlOptions'];
$parameterArray = $this->data['parameterArray'];
$elementName = $parameterArray['itemFormElName'];
$config = $parameterArray['fieldConf']['config'];
$type = $config['type'];
// Remove any white-spaces from the allowed extension lists
$allowed = implode(',', GeneralUtility::trimExplode(',', (string)($config['allowed'] ?? ''), true));
if (isset($config['readOnly']) && $config['readOnly']) {
return [];
}
if ($options['title'] ?? false) {
$title = $options['title'];
} elseif ($type === 'group') {
$title = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.browse_db';
} elseif ($type === 'folder') {
$title = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.browse_folder';
} else {
// FieldControl requires to provide a title -> Set default if non is given and custom TCA config is used
$title = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.browse_elements';
}
// Check against inline uniqueness - Create some onclick js for delete control and element browser
// to override record selection in some FAL scenarios - See 'appearance' docs of group element
$objectPrefix = '';
if (($this->data['isInlineChild'] ?? false)
&& ($this->data['inlineParentUid'] ?? false)
&& ($this->data['inlineParentConfig']['foreign_table'] ?? false) === $table
&& ($this->data['inlineParentConfig']['foreign_unique'] ?? false) === $fieldName
) {
$objectPrefix = $this->inlineStackProcessor->getDomObjectIdPrefixFromStructure($this->data['inlineStructure'], $this->data['inlineFirstPid']) . '-' . $table;
}
if ($type === 'group') {
if (($this->data['inlineParentConfig']['type'] ?? '') === 'file' || ($config['allowed'] ?? '') === 'sys_file') {
$elementBrowserType = 'file';
// Remove any white-spaces from the allowed extension lists
$allowed = implode(',', GeneralUtility::trimExplode(',', (string)($this->data['inlineParentConfig']['allowed'] ?? ''), true));
} else {
$elementBrowserType = 'db';
}
} else {
$elementBrowserType = 'folder';
}
// Initialize link attributes
$linkAttributes = [
'class' => 't3js-element-browser',
'data-mode' => $elementBrowserType,
'data-field-reference' => $elementName,
'data-allowed-types' => $allowed,
'data-irre-object-id' => $objectPrefix,
'data-use-events' => 'true',
];
// Add the default entry point - if found
$linkAttributes = $this->addEntryPoint($table, $fieldName, $config, $linkAttributes);
return [
'iconIdentifier' => 'actions-insert-record',
'title' => $title,
'linkAttributes' => $linkAttributes,
];
}
/**
* Try to resolve a configured default entry point - page / folder
* to be expanded - and add it to the link attributes if found.
*/
protected function addEntryPoint(string $table, string $fieldName, array $fieldConfig, array $linkAttributes): array
{
if (!isset($fieldConfig['elementBrowserEntryPoints']) || !is_array($fieldConfig['elementBrowserEntryPoints'])) {
// Early return in case no entry points are defined
return $linkAttributes;
}
// Fetch the configured default entry point (which might be a marker)
$entryPoint = (string)($fieldConfig['elementBrowserEntryPoints']['_default'] ?? '');
// In case no default entry point is given, check if we deal with type=db and only one allowed table
if ($entryPoint === '') {
if ($fieldConfig['type'] === 'folder') {
// Return for type folder as this requires the "_default" key to be set
return $linkAttributes;
}
// Check for the allowed tables, if only one table is allowed check if an entry point is defined for it
$allowed = GeneralUtility::trimExplode(',', $fieldConfig['allowed'] ?? '', true);
if (count($allowed) === 1 && isset($fieldConfig['elementBrowserEntryPoints'][$allowed[0]])) {
// Use the entry point for the single table as default
$entryPoint = (string)$fieldConfig['elementBrowserEntryPoints'][$allowed[0]];
}
if ($entryPoint === '') {
// Return if still empty
return $linkAttributes;
}
}
// Check and resolve possible marker
if (str_starts_with($entryPoint, '###') && str_ends_with($entryPoint, '###')) {
if ($entryPoint === '###CURRENT_PID###') {
// Use the current pid
$entryPoint = (string)$this->data['effectivePid'];
} elseif ($entryPoint === '###SITEROOT###' && ($this->data['site'] ?? null) instanceof Site) {
// Use the root page id from the current site
$entryPoint = (string)$this->data['site']->getRootPageId();
} else {
// Check for special TSconfig marker
$TSconfig = FormEngineUtility::getTCEFORM_TSconfig($table, ['pid' => $this->data['effectivePid']]);
$keyword = substr($entryPoint, 3, -3);
if (str_starts_with($keyword, 'PAGE_TSCONFIG_')) {
$entryPoint = (string)($TSconfig[$fieldName][$keyword] ?? '');
} else {
$entryPoint = (string)($TSconfig['_' . $keyword] ?? '');
}
}
}
// Add the entry point to the link attribute - if resolved
if ($entryPoint !== '') {
$linkAttributes['data-entry-point'] = $entryPoint;
}
return $linkAttributes;
}
}
@@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Backend\Form\FieldControl;
use TYPO3\CMS\Backend\Form\AbstractNode;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction;
use TYPO3\CMS\Core\Utility\StringUtility;
/**
* Renders the icon "insert record from clipboard",
* typically used for type=group.
*/
class InsertClipboard extends AbstractNode
{
/**
* Add button control
*
* @return array As defined by FieldControl class
*/
public function render(): array
{
$languageService = $this->getLanguageService();
$parameterArray = $this->data['parameterArray'];
$elementName = $parameterArray['itemFormElName'];
$config = $parameterArray['fieldConf']['config'];
$clipboardElements = $config['clipboardElements'];
if ((isset($config['readOnly']) && $config['readOnly'])
|| empty($clipboardElements)
) {
return [];
}
$dataAttributes = [
'element' => $elementName,
'clipboardItems' => [],
];
$title = sprintf($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.clipInsert_db'), count($clipboardElements));
foreach ($clipboardElements as $clipboardElement) {
$dataAttributes['clipboardItems'][] = [
'title' => $clipboardElement['title'],
'value' => $clipboardElement['value'],
];
}
$id = StringUtility::getUniqueId('t3js-formengine-fieldcontrol-');
return [
'iconIdentifier' => 'actions-document-paste-into',
'title' => $title,
'linkAttributes' => [
'id' => $id,
'data-element' => $dataAttributes['element'],
'data-clipboard-items' => json_encode($dataAttributes['clipboardItems']),
],
'javaScriptModules' => [
JavaScriptModuleInstruction::create('@typo3/backend/form-engine/field-control/insert-clipboard.js')->instance('#' . $id),
],
];
}
protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}
}
+109
View File
@@ -0,0 +1,109 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Backend\Form\FieldControl;
use TYPO3\CMS\Backend\Form\AbstractNode;
use TYPO3\CMS\Backend\Form\Behavior\OnFieldChangeTrait;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Crypto\HashService;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction;
use TYPO3\CMS\Core\Utility\StringUtility;
/**
* Renders the icon with link parameters to open the element browser.
* Used in InputLinkElement.
*/
class LinkPopup extends AbstractNode
{
use OnFieldChangeTrait;
public function __construct(
private readonly UriBuilder $uriBuilder,
private readonly HashService $hashService,
) {}
/**
* Link popup control
*
* @return array As defined by FieldControl class
*/
public function render(): array
{
$options = $this->data['renderData']['fieldControlOptions'];
$title = $options['title'] ?? 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.link';
$parameterArray = $this->data['parameterArray'];
$itemName = $parameterArray['itemFormElName'];
$linkBrowserArguments = [];
if (is_array($options['allowedTypes'] ?? false)) {
$linkBrowserArguments['allowedTypes'] = implode(',', $options['allowedTypes']);
} elseif (isset($options['blindLinkOptions'])) {
// @todo Deprecate this option
$linkBrowserArguments['blindLinkOptions'] = $options['blindLinkOptions'];
}
if (is_array($options['allowedOptions'] ?? false)) {
$linkBrowserArguments['allowedOptions'] = implode(',', $options['allowedOptions']);
} elseif (isset($options['blindLinkFields'])) {
// @todo Deprecate this option
$linkBrowserArguments['blindLinkFields'] = $options['blindLinkFields'];
}
if (is_array($options['allowedFileExtensions'] ?? false)) {
$linkBrowserArguments['allowedFileExtensions'] = implode(',', $options['allowedFileExtensions']);
} elseif (isset($options['allowedExtensions'])) {
// @todo Deprecate this option
$linkBrowserArguments['allowedExtensions'] = $options['allowedExtensions'];
}
$urlParameters = array_merge(
[
'params' => $linkBrowserArguments,
'table' => $this->data['tableName'],
'uid' => $this->data['databaseRow']['uid'],
'pid' => $this->data['databaseRow']['pid'],
'field' => $this->data['fieldName'],
'formName' => 'editform',
'itemName' => $itemName,
'hmac' => $this->hashService->hmac('editform' . $itemName, 'wizard_js'),
],
$this->forwardOnFieldChangeQueryParams($parameterArray['fieldChangeFunc'] ?? [])
);
$url = (string)$this->uriBuilder->buildUriFromRoute('wizard_link', ['P' => $urlParameters]);
$id = StringUtility::getUniqueId('t3js-formengine-fieldcontrol-');
$label = $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_browse_links.xlf:openLinkWizard');
return [
'iconIdentifier' => 'actions-wizard-link',
'title' => $title,
'linkAttributes' => [
'id' => $id,
'href' => $url,
'data-item-name' => $itemName,
'aria-label' => $label,
],
'javaScriptModules' => [
JavaScriptModuleInstruction::create('@typo3/backend/form-engine/field-control/link-popup.js')->instance('#' . $id),
],
];
}
protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}
}
+110
View File
@@ -0,0 +1,110 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Backend\Form\FieldControl;
use TYPO3\CMS\Backend\Form\AbstractNode;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
/**
* Renders the icon with link parameters to jump to the records module
* "single table" view, showing only one configurable table.
*/
class ListModule extends AbstractNode
{
public function __construct(
private readonly UriBuilder $uriBuilder,
) {}
/**
* Add button control
*
* @return array As defined by FieldControl class
*/
public function render(): array
{
$options = $this->data['renderData']['fieldControlOptions'];
$parameterArray = $this->data['parameterArray'];
// Handle options and fallback
$title = $options['title'] ?? 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.list';
$table = '';
if (isset($options['table'])) {
// Table given in options - use it
$table = $options['table'];
} elseif ($parameterArray['fieldConf']['config']['type'] === 'group'
&& !empty($parameterArray['fieldConf']['config']['allowed'])
) {
// Use first table from allowed list if specific table is not set in options
$allowedTables = GeneralUtility::trimExplode(',', $parameterArray['fieldConf']['config']['allowed'], true);
$table = array_pop($allowedTables);
} elseif ($parameterArray['fieldConf']['config']['type'] === 'select'
&& !empty($parameterArray['fieldConf']['config']['foreign_table'])
) {
// Use foreign_table if given for type=select
$table = $parameterArray['fieldConf']['config']['foreign_table'];
}
if (empty($table)) {
// Still no table - this element can not handle the list control.
return [];
}
// Target pid of new records is current pid by default
$pid = $this->data['effectivePid'];
if (isset($options['pid'])) {
// pid configured in options - use it
$pid = $options['pid'];
} elseif (
$this->data['tcaSchemata']->has($table)
&& ($this->data['tcaSchemata']->get($table)->getRawConfiguration()['rootLevel'] ?? false) === 1
) {
// Target table can only exist on root level - set 0 as pid
$pid = 0;
}
$urlParameters = [
'P' => [
'params' => [
'table' => $table,
'pid' => $pid,
],
'table' => $this->data['tableName'],
'field' => $this->data['fieldName'],
'uid' => $this->data['databaseRow']['uid'],
'returnUrl' => $this->data['returnUrl'],
],
];
$id = StringUtility::getUniqueId('t3js-formengine-fieldcontrol-');
return [
'iconIdentifier' => 'actions-list-alternative',
'title' => $title,
'linkAttributes' => [
'id' => $id,
'href' => (string)$this->uriBuilder->buildUriFromRoute('wizard_list', $urlParameters),
],
'javaScriptModules' => [
JavaScriptModuleInstruction::create('@typo3/backend/form-engine/field-control/list-module.js')->instance('#' . $id),
],
];
}
}
@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Backend\Form\FieldControl;
use TYPO3\CMS\Backend\Form\AbstractNode;
use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction;
use TYPO3\CMS\Core\Utility\StringUtility;
/**
* Renders a widget to generate a random string in JavaScript.
*
* 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
{
$options = $this->data['renderData']['fieldControlOptions'];
$itemName = (string)$this->data['parameterArray']['itemFormElName'];
$id = StringUtility::getUniqueId('t3js-formengine-fieldcontrol-');
// Handle options and fallback
$title = $options['title'] ?? 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.generatePassword';
$linkAttributes = [
'id' => $id,
'data-item-name' => $itemName,
];
if ($options['allowEdit'] ?? true) {
$linkAttributes['data-allow-edit'] = true;
}
if (is_string($options['passwordPolicy'] ?? null) && $options['passwordPolicy'] !== '') {
$linkAttributes['data-password-policy'] = $options['passwordPolicy'];
}
return [
'iconIdentifier' => 'actions-dice',
'title' => $title,
'linkAttributes' => $linkAttributes,
'javaScriptModules' => [
JavaScriptModuleInstruction::create('@typo3/backend/form-engine/field-control/password-generator.js')->instance($id),
],
];
}
}
@@ -0,0 +1,69 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Backend\Form\FieldControl;
use TYPO3\CMS\Backend\Form\AbstractNode;
use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction;
use TYPO3\CMS\Core\Utility\StringUtility;
/**
* "Reset selection to previous selected items" icon,
* typically used by type=select with renderType=selectSingleBox
*/
class ResetSelection extends AbstractNode
{
/**
* Add button control
*
* @return array As defined by FieldControl class
*/
public function render(): array
{
$parameterArray = $this->data['parameterArray'];
$selectItems = $parameterArray['fieldConf']['config']['items'];
if (($parameterArray['fieldConf']['config']['readOnly'] ?? false) || empty($selectItems)) {
// Early return if the field is readOnly or no items exist
return [];
}
$itemName = $parameterArray['itemFormElName'];
$itemArray = array_flip($parameterArray['itemFormElValue']);
$initiallySelectedIndices = [];
foreach ($selectItems as $i => $item) {
$value = $item['value'];
// Selected or not by default
if (isset($itemArray[$value])) {
$initiallySelectedIndices[] = $i;
}
}
$id = StringUtility::getUniqueId('t3js-formengine-fieldcontrol-');
return [
'iconIdentifier' => 'actions-edit-undo',
'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.revertSelection',
'linkAttributes' => [
'id' => $id,
'data-item-name' => $itemName,
'data-selected-indices' => json_encode($initiallySelectedIndices),
],
'javaScriptModules' => [
JavaScriptModuleInstruction::create('@typo3/backend/form-engine/field-control/reset-selection.js')->instance('#' . $id),
],
];
}
}