Passed
Push — master ( f627a2...fe3dee )
by
unknown
14:46
created

UserFunctions::getSiteLanguageTitle()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 2
nc 1
nop 1
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
18
namespace TYPO3\CMS\Backend\Configuration\TCA;
19
20
use TYPO3\CMS\Core\Localization\LanguageService;
21
use TYPO3\CMS\Core\Utility\CommandUtility;
22
use TYPO3\CMS\Core\Utility\GeneralUtility;
23
24
/**
25
 * This class provides user functions for the usage in TCA definition
26
 * @internal
27
 */
28
class UserFunctions
29
{
30
    /**
31
     * Used to build the IRRE title of a site language element
32
     *
33
     * @param array $parameters
34
     */
35
    public function getSiteLanguageTitle(array &$parameters): void
36
    {
37
        $record = $parameters['row'];
38
        $parameters['title'] = sprintf(
39
            '%s %s [%d] (%s) Base: %s',
40
            $record['enabled'] ? '' : '[' . $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:disabled') . ']',
41
            $record['title'],
42
            $record['languageId'][0],
43
            $record['locale'],
44
            $record['base']
45
        );
46
    }
47
48
    /**
49
     * Used to build the IRRE title of a site route element
50
     *
51
     * @param array $parameters
52
     */
53
    public function getRouteTitle(array &$parameters): void
54
    {
55
        $record = $parameters['row'];
56
        if ($record['type'][0] === 'uri') {
57
            $parameters['title'] = sprintf(
58
                '%s %s %s',
59
                $record['route'],
60
                $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site.routes.irreHeader.redirectsTo'),
61
                $record['source'] ?: '[' . $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:undefined') . ']'
62
            );
63
        } else {
64
            $parameters['title'] = $record['route'];
65
        }
66
    }
67
68
    /**
69
     * Used to build the IRRE title of a site error handling element
70
     * @param array $parameters
71
     */
72
    public function getErrorHandlingTitle(array &$parameters): void
73
    {
74
        $record = $parameters['row'];
75
        $format = '%s: %s';
76
        $arguments = [$record['errorCode']];
77
        switch ($record['errorHandler'][0]) {
78
            case 'Fluid':
79
                $arguments[] = $record['errorFluidTemplate'];
80
                break;
81
            case 'Page':
82
                $arguments[] = $record['errorContentSource'];
83
                break;
84
            case 'PHP':
85
                $arguments[] = $record['errorPhpClassFQCN'];
86
                break;
87
            default:
88
                $arguments[] = $record['errorHandler'][0];
89
        }
90
        $parameters['title'] = sprintf($format, ...$arguments);
91
    }
92
93
    public static function getAllSystemLocales(): array
94
    {
95
        $disabledFunctions = GeneralUtility::trimExplode(',', (string)ini_get('disable_functions'), true);
96
        if (in_array('exec', $disabledFunctions, true)) {
97
            return [];
98
        }
99
100
        $rawOutput = [];
101
        CommandUtility::exec('locale -a', $rawOutput);
102
103
        ksort($rawOutput, SORT_NATURAL);
104
        $locales = [];
105
        foreach ($rawOutput as $item) {
106
            $locales[] = [$item, $item];
107
        }
108
109
        return $locales;
110
    }
111
112
    protected function getLanguageService(): LanguageService
113
    {
114
        return $GLOBALS['LANG'];
115
    }
116
}
117