‪TYPO3CMS  9.5
UserFileMountService.php
Go to the documentation of this file.
1 <?php
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 
24 
33 {
41  public function ‪renderTceformsSelectDropdown(&$PA)
42  {
43  $allowedStorageIds = array_map(
44  function (\‪TYPO3\CMS\Core\Resource\‪ResourceStorage $storage) {
45  return $storage->getUid();
46  },
48  );
49  // If working for sys_filemounts table
50  $storageUid = (int)$PA['row']['base'][0];
51  if (!$storageUid) {
52  // If working for sys_file_collection table
53  $storageUid = (int)$PA['row']['storage'][0];
54  }
55  if ($storageUid > 0 && in_array($storageUid, $allowedStorageIds, true)) {
57  $storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
59  $storage = $storageRepository->findByUid($storageUid);
60  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 {
94  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
95  $queue = $flashMessageService->getMessageQueueByIdentifier();
96  $queue->enqueue(new ‪FlashMessage('Storage "' . $storage->getName() . '" is not browsable. No folder is currently selectable.', '', ‪FlashMessage::WARNING));
97  if (empty($PA['items'])) {
98  $PA['items'][] = [
99  $PA['row'][$PA['field']],
100  $PA['row'][$PA['field']]
101  ];
102  }
103  }
104  } else {
105  $PA['items'][] = ['', 'Please choose a FAL mount from above first.'];
106  }
107  }
108 
117  protected function ‪getSubfoldersForOptionList(‪Folder $parentFolder, $level = 0)
118  {
119  $level++;
120  // hard break on recursion
121  if ($level > 99) {
122  return [];
123  }
124  $allFolderItems = [$parentFolder];
125  $subFolders = $parentFolder->‪getSubfolders();
126  foreach ($subFolders as $subFolder) {
127  try {
128  $subFolderItems = $this->‪getSubfoldersForOptionList($subFolder, $level);
130  $subFolderItems = [];
131  }
132  $allFolderItems = array_merge($allFolderItems, $subFolderItems);
133  }
134  return $allFolderItems;
135  }
136 
143  {
144  return ‪$GLOBALS['BE_USER'];
145  }
146 }
‪TYPO3
‪TYPO3\CMS\Core\Resource\Service\UserFileMountService
Definition: UserFileMountService.php:33
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getFileStorages
‪TYPO3 CMS Core Resource ResourceStorage[] getFileStorages()
Definition: BackendUserAuthentication.php:1851
‪TYPO3\CMS\Core\Resource\Service\UserFileMountService\getBackendUserAuthentication
‪BackendUserAuthentication getBackendUserAuthentication()
Definition: UserFileMountService.php:142
‪TYPO3\CMS\Core\Resource\Service
Definition: FileProcessingService.php:2
‪TYPO3\CMS\Core\Messaging\AbstractMessage\WARNING
‪const WARNING
Definition: AbstractMessage.php:28
‪TYPO3\CMS\Core\Resource\Service\UserFileMountService\getSubfoldersForOptionList
‪Folder[] getSubfoldersForOptionList(Folder $parentFolder, $level=0)
Definition: UserFileMountService.php:117
‪TYPO3\CMS\Core\Resource\Folder\getSubfolders
‪Folder[] getSubfolders($start=0, $numberOfItems=0, $filterMode=self::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, $recursive=false)
Definition: Folder.php:287
‪TYPO3\CMS\Core\Resource\Service\UserFileMountService\renderTceformsSelectDropdown
‪renderTceformsSelectDropdown(&$PA)
Definition: UserFileMountService.php:41
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:34
‪TYPO3\CMS\Core\Resource\StorageRepository
Definition: StorageRepository.php:29
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:74
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:25
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:29
‪TYPO3\CMS\Core\Resource\Exception\InsufficientFolderReadPermissionsException
Definition: InsufficientFolderReadPermissionsException.php:21