[TASK] Further improvements for the site configuration
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Configuration / TCA / UserFunctions.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Backend\Configuration\TCA;
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
18 use TYPO3\CMS\Core\Localization\LanguageService;
19
20 /**
21 * This class provides user functions for the usage in TCA definition
22 * @internal
23 */
24 class UserFunctions
25 {
26 /**
27 * Used to build the IRRE title of a site language element
28 *
29 * @param array $parameters
30 */
31 public function getSiteLanguageTitle(array &$parameters): void
32 {
33 $record = $parameters['row'];
34 $parameters['title'] = sprintf(
35 '%s %s (%s) Base: %s',
36 $record['enabled'] ? '' : '[' . $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:disabled') . ']',
37 $record['title'],
38 $record['locale'],
39 $record['base']
40 );
41 }
42
43 /**
44 * Used to build the IRRE title of a site route element
45 *
46 * @param array $parameters
47 */
48 public function getRouteTitle(array &$parameters): void
49 {
50 $record = $parameters['row'];
51 if ($record['type'][0] === 'uri') {
52 $parameters['title'] = sprintf(
53 '%s %s %s',
54 $record['route'],
55 $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site.routes.irreHeader.redirectsTo'),
56 $record['source'] ?: '[' . $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:undefined') . ']'
57 );
58 } else {
59 $parameters['title'] = $record['route'];
60 }
61 }
62
63 /**
64 * Used to build the IRRE title of a site error handling element
65 * @param array $parameters
66 */
67 public function getErrorHandlingTitle(array &$parameters): void
68 {
69 $record = $parameters['row'];
70 $format = '%s: %s';
71 $arguments = [$record['errorCode']];
72 switch ($record['errorHandler'][0]) {
73 case 'Fluid':
74 $arguments[] = $record['errorFluidTemplate'];
75 break;
76 case 'Page':
77 $arguments[] = $record['errorContentSource'];
78 break;
79 case 'PHP':
80 $arguments[] = $record['errorPhpClassFQCN'];
81 break;
82 default:
83 $arguments[] = $record['errorHandler'][0];
84 }
85 $parameters['title'] = sprintf($format, ...$arguments);
86 }
87
88 /**
89 * @return LanguageService
90 */
91 protected function getLanguageService(): LanguageService
92 {
93 return $GLOBALS['LANG'];
94 }
95 }