876a3b1b2b065c08551ee2d77468d91be7fdc0c7
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Resource / Utility / ListUtility.php
1 <?php
2 namespace TYPO3\CMS\Core\Resource\Utility;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Localization\LanguageService;
18 use TYPO3\CMS\Core\Resource\FolderInterface;
19
20 /**
21 * Utility function for working with resource-lists
22 */
23 class ListUtility
24 {
25 /**
26 * Resolve special folders (by their role) into localised string
27 *
28 * @param array $folders Array of \TYPO3\CMS\Core\Resource\Folder
29 * @return array Array of \TYPO3\CMS\Core\Resource\Folder; folder name or role with folder name as keys
30 */
31 public static function resolveSpecialFolderNames(array $folders)
32 {
33 /** @var LanguageService $lang */
34 $lang = $GLOBALS['LANG'];
35 $resolvedFolders = [];
36
37 /** @var \TYPO3\CMS\Core\Resource\Folder $folder */
38 foreach ($folders as $folder) {
39 $name = $folder->getName();
40 $role = $folder->getRole();
41 if ($role !== FolderInterface::ROLE_DEFAULT) {
42 $tempName = htmlspecialchars($lang->sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:role_folder_' . $role));
43 if (!empty($tempName) && ($tempName !== $name)) {
44 // Set new name and append original name
45 $name = $tempName . ' (' . $name . ')';
46 }
47 }
48 $resolvedFolders[$name] = $folder;
49 }
50
51 return $resolvedFolders;
52 }
53 }