‪TYPO3CMS  11.5
UserFileMountService.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
26 
35 {
43  public function ‪renderTceformsSelectDropdown(&$PA)
44  {
45  $allowedStorageIds = array_map(
46  static function (‪ResourceStorage $storage) {
47  return $storage->‪getUid();
48  },
50  );
51  // If working for sys_filemounts table
52  $storageUid = (int)($PA['row']['base'][0] ?? 0);
53  if (!$storageUid) {
54  // If working for sys_file_collection table
55  $storageUid = (int)($PA['row']['storage'][0] ?? 0);
56  }
57  if ($storageUid > 0 && in_array($storageUid, $allowedStorageIds, true)) {
58  $storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
60  $storage = $storageRepository->findByUid($storageUid);
61  if ($storage === null) {
62  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
63  $queue = $flashMessageService->getMessageQueueByIdentifier();
64  $queue->enqueue(new ‪FlashMessage('Storage #' . $storageUid . ' does not exist. No folder is currently selectable.', '', ‪FlashMessage::ERROR));
65  if (empty($PA['items'])) {
66  $PA['items'][] = [
67  $PA['row'][$PA['field']],
68  $PA['row'][$PA['field']],
69  ];
70  }
71  } elseif ($storage->‪isBrowsable()) {
72  $rootLevelFolders = [];
73 
74  $fileMounts = $storage->‪getFileMounts();
75  if (!empty($fileMounts)) {
76  foreach ($fileMounts as $fileMountInfo) {
77  $rootLevelFolders[] = $fileMountInfo['folder'];
78  }
79  } else {
80  $rootLevelFolders[] = $storage->‪getRootLevelFolder();
81  }
82 
83  foreach ($rootLevelFolders as $rootLevelFolder) {
84  $folderItems = $this->‪getSubfoldersForOptionList($rootLevelFolder);
85  foreach ($folderItems as $item) {
86  $PA['items'][] = [
87  $item->getIdentifier(),
88  $item->getIdentifier(),
89  ];
90  }
91  }
92  } else {
93  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
94  $queue = $flashMessageService->getMessageQueueByIdentifier();
95  $queue->enqueue(new ‪FlashMessage('Storage "' . $storage->‪getName() . '" is not browsable. No folder is currently selectable.', '', ‪FlashMessage::WARNING));
96  if (empty($PA['items'])) {
97  $PA['items'][] = [
98  $PA['row'][$PA['field']],
99  $PA['row'][$PA['field']],
100  ];
101  }
102  }
103  } else {
104  $PA['items'][] = ['', 'Please choose a FAL mount from above first.'];
105  }
106  }
107 
116  protected function ‪getSubfoldersForOptionList(‪Folder $parentFolder, $level = 0)
117  {
118  $level++;
119  // hard break on recursion
120  if ($level > 99) {
121  return [];
122  }
123  $allFolderItems = [$parentFolder];
124  $subFolders = $parentFolder->getSubfolders();
125  foreach ($subFolders as $subFolder) {
126  try {
127  $subFolderItems = $this->‪getSubfoldersForOptionList($subFolder, $level);
129  $subFolderItems = [];
130  }
131  $allFolderItems = array_merge($allFolderItems, $subFolderItems);
132  }
133  return $allFolderItems;
134  }
135 
142  {
143  return ‪$GLOBALS['BE_USER'];
144  }
145 }
‪TYPO3\CMS\Core\Resource\ResourceStorage\getUid
‪int getUid()
Definition: ResourceStorage.php:330
‪TYPO3\CMS\Core\Resource\Service\UserFileMountService
Definition: UserFileMountService.php:35
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getFileStorages
‪TYPO3 CMS Core Resource ResourceStorage[] getFileStorages()
Definition: BackendUserAuthentication.php:1506
‪TYPO3\CMS\Core\Resource\ResourceStorage\getRootLevelFolder
‪Folder getRootLevelFolder($respectFileMounts=true)
Definition: ResourceStorage.php:2654
‪TYPO3\CMS\Core\Resource\Service\UserFileMountService\getBackendUserAuthentication
‪BackendUserAuthentication getBackendUserAuthentication()
Definition: UserFileMountService.php:141
‪TYPO3\CMS\Core\Resource\Service
Definition: ConfigurationService.php:18
‪TYPO3\CMS\Core\Messaging\AbstractMessage\WARNING
‪const WARNING
Definition: AbstractMessage.php:30
‪TYPO3\CMS\Core\Resource\Service\UserFileMountService\getSubfoldersForOptionList
‪Folder[] getSubfoldersForOptionList(Folder $parentFolder, $level=0)
Definition: UserFileMountService.php:116
‪TYPO3\CMS\Core\Resource\Service\UserFileMountService\renderTceformsSelectDropdown
‪renderTceformsSelectDropdown(&$PA)
Definition: UserFileMountService.php:43
‪TYPO3\CMS\Core\Resource\ResourceStorage\isBrowsable
‪bool isBrowsable()
Definition: ResourceStorage.php:413
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:37
‪TYPO3\CMS\Core\Resource\StorageRepository
Definition: StorageRepository.php:38
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Resource\ResourceStorage\getFileMounts
‪array getFileMounts()
Definition: ResourceStorage.php:598
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:125
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:26
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:27
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31
‪TYPO3\CMS\Core\Resource\ResourceStorage\getName
‪string getName()
Definition: ResourceStorage.php:320
‪TYPO3\CMS\Core\Resource\Exception\InsufficientFolderReadPermissionsException
Definition: InsufficientFolderReadPermissionsException.php:21