Extending the user settings
Deprecated since version 14.2
The method
\TYPO3\
has been deprecated in favor of the new
add method.
Adding fields to User Settings is done in a TCA Overrides file.
Here is an example taken from the "examples" extension:
<?php
declare(strict_types=1);
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
ExtensionManagementUtility::addUserSetting(
'mobile',
[
'label' => 'LLL:examples.db:be_users.tx_examples_mobile',
'config' => [
'type' => 'input',
],
],
'after:email',
);
The third parameter in the call to
add
is used to position the new field. In this example we add it
after the existing "email" field.
The new field is then displayed in the user settings after clearing the caches.
TCA available for the user settings module
The user_ TCA column has the following structure:
columns-
Array of field configurations, each containing:
label- The field label (LLL reference or string)
config- Standard TCA config array (type, renderType, items, etc.)
table(optional)- Set to
'be_if the field is stored in a be_users table columnusers'
showitem- Comma-separated list of fields to display, supports
--for tabsdiv--;
Available field types:
input- Text input fieldnumber- Number input fieldemail- Email input fieldpassword- Password input fieldcheckwith :render- Checkbox/toggleType => 'checkbox Toggle' selectwithrender- Select dropdownType => 'select Single' language- Language selector
"On Click" / "On Confirmation" JavaScript Callbacks
PSR-14 event AddUserSettingsJavaScriptModulesEvent can be used to inject a JavaScript module to handle custom JavaScript events.
Migration from addFieldsToUserSettings to addUserSetting
Replace the two-step approach with the new
add method.
Note that the new method uses TCA-style configuration and should be called from
Configuration/TCA/Overrides/be_users.php instead of ext_tables.php.
Before:
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
$GLOBALS['TYPO3_USER_SETTINGS']['columns']['myCustomSetting'] = [
'type' => 'check',
'label' => 'my_extension.messages:myCustomSetting',
];
ExtensionManagementUtility::addFieldsToUserSettings(
'myCustomSetting',
'after:emailMeAtLogin'
);
After:
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
ExtensionManagementUtility::addUserSetting(
'myCustomSetting',
[
'label' => 'my_extension.messages:myCustomSetting',
'config' => [
'type' => 'check',
'renderType' => 'checkboxToggle',
],
],
'after:emailMeAtLogin'
);