‪TYPO3CMS  11.5
UserFunctions.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 
24 
30 {
36  public function ‪getSiteLanguageTitle(array &$parameters): void
37  {
38  $record = $parameters['row'];
39  $languageId = (int)($record['languageId'][0] ?? 0);
40 
41  if ($languageId === PHP_INT_MAX && str_starts_with((string)($record['uid'] ?? ''), 'NEW')) {
42  // If we deal with a new record, created via "Create new" (indicated by the PHP_INT_MAX placeholder),
43  // we use a label as record title, until the real values, especially the language ID, are calculated.
44  $parameters['title'] = '[' . $this->‪getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site.languages.new') . ']';
45  return;
46  }
47 
48  $parameters['title'] = sprintf(
49  '%s %s [%d] (%s) Base: %s',
50  $record['enabled'] ? '' : '[' . $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:disabled') . ']',
51  $record['title'],
52  $languageId,
53  $record['locale'],
54  $record['base']
55  );
56  }
57 
63  public function ‪getRouteTitle(array &$parameters): void
64  {
65  $record = $parameters['row'];
66  if (($record['type'][0] ?? false) === 'uri') {
67  $parameters['title'] = sprintf(
68  '%s %s %s',
69  $record['route'],
70  $this->‪getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site.routes.irreHeader.redirectsTo'),
71  $record['source'] ?: '[' . $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:undefined') . ']'
72  );
73  } else {
74  $parameters['title'] = $record['route'];
75  }
76  }
77 
82  public function ‪getErrorHandlingTitle(array &$parameters): void
83  {
84  $record = $parameters['row'];
85  $format = '%s: %s';
86  $arguments = [$record['errorCode']];
87  switch ($record['errorHandler'][0] ?? false) {
88  case 'Fluid':
89  $arguments[] = $record['errorFluidTemplate'];
90  break;
91  case 'Page':
92  $arguments[] = $record['errorContentSource'];
93  break;
94  case 'PHP':
95  $arguments[] = $record['errorPhpClassFQCN'];
96  break;
97  default:
98  $arguments[] = $record['errorHandler'][0] ?? '';
99  }
100  $parameters['title'] = sprintf($format, ...$arguments);
101  }
102 
103  public static function ‪getAllSystemLocales(): array
104  {
105  $disabledFunctions = ‪GeneralUtility::trimExplode(',', (string)ini_get('disable_functions'), true);
106  if (in_array('exec', $disabledFunctions, true)) {
107  return [];
108  }
109 
110  $rawOutput = [];
111  ‪CommandUtility::exec('locale -a', $rawOutput);
112 
113  sort($rawOutput, SORT_NATURAL);
114  $locales = [];
115  $usedLocales = [];
116  foreach ($rawOutput as $item) {
117  // do not show C/POSIX in the list of locales, as this is the default anyway
118  $obj = new ‪Locale($item);
119  if ($obj->getPosixCodeSet() === 'C' || $obj->getPosixCodeSet() === 'POSIX') {
120  continue;
121  }
122  // Skip locales with appended language or country code (e.g. "de_DE.UTF-8", "de_DE.ISO8859-1").
123  // The user should only choose "de_DE".
124  if (in_array($obj->getName(), $usedLocales, true)) {
125  continue;
126  }
127  $locales[] = [$item, $item];
128  $usedLocales[] = $obj->getName();
129  }
130 
131  return $locales;
132  }
133 
135  {
136  return ‪$GLOBALS['LANG'];
137  }
138 }
‪TYPO3\CMS\Backend\Configuration\TCA\UserFunctions\getAllSystemLocales
‪static getAllSystemLocales()
Definition: UserFunctions.php:103
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:999
‪TYPO3\CMS\Backend\Configuration\TCA\UserFunctions
Definition: UserFunctions.php:30
‪TYPO3\CMS\Core\Utility\CommandUtility\exec
‪static string exec($command, &$output=null, &$returnValue=0)
Definition: CommandUtility.php:81
‪TYPO3\CMS\Backend\Configuration\TCA\UserFunctions\getLanguageService
‪getLanguageService()
Definition: UserFunctions.php:134
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\Locale
Definition: Locale.php:30
‪TYPO3\CMS\Backend\Configuration\TCA\UserFunctions\getSiteLanguageTitle
‪getSiteLanguageTitle(array &$parameters)
Definition: UserFunctions.php:36
‪TYPO3\CMS\Backend\Configuration\TCA
Definition: ItemsProcessorFunctions.php:18
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Backend\Configuration\TCA\UserFunctions\getErrorHandlingTitle
‪getErrorHandlingTitle(array &$parameters)
Definition: UserFunctions.php:82
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Utility\CommandUtility
Definition: CommandUtility.php:49
‪TYPO3\CMS\Backend\Configuration\TCA\UserFunctions\getRouteTitle
‪getRouteTitle(array &$parameters)
Definition: UserFunctions.php:63