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