‪TYPO3CMS  10.4
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  function (‪ResourceStorage $storage) {
47  return $storage->‪getUid();
48  },
50  );
51  // If working for sys_filemounts table
52  $storageUid = (int)$PA['row']['base'][0];
53  if (!$storageUid) {
54  // If working for sys_file_collection table
55  $storageUid = (int)$PA['row']['storage'][0];
56  }
57  if ($storageUid > 0 && in_array($storageUid, $allowedStorageIds, true)) {
59  $storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
61  $storage = $storageRepository->findByUid($storageUid);
62  if ($storage === null) {
64  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
65  $queue = $flashMessageService->getMessageQueueByIdentifier();
66  $queue->enqueue(new ‪FlashMessage('Storage #' . $storageUid . ' does not exist. No folder is currently selectable.', '', ‪FlashMessage::ERROR));
67  if (empty($PA['items'])) {
68  $PA['items'][] = [
69  $PA['row'][$PA['field']],
70  $PA['row'][$PA['field']]
71  ];
72  }
73  } elseif ($storage->‪isBrowsable()) {
74  $rootLevelFolders = [];
75 
76  $fileMounts = $storage->‪getFileMounts();
77  if (!empty($fileMounts)) {
78  foreach ($fileMounts as $fileMountInfo) {
79  $rootLevelFolders[] = $fileMountInfo['folder'];
80  }
81  } else {
82  $rootLevelFolders[] = $storage->‪getRootLevelFolder();
83  }
84 
85  foreach ($rootLevelFolders as $rootLevelFolder) {
86  $folderItems = $this->‪getSubfoldersForOptionList($rootLevelFolder);
87  foreach ($folderItems as $item) {
88  $PA['items'][] = [
89  $item->getIdentifier(),
90  $item->getIdentifier()
91  ];
92  }
93  }
94  } else {
96  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
97  $queue = $flashMessageService->getMessageQueueByIdentifier();
98  $queue->enqueue(new ‪FlashMessage('Storage "' . $storage->‪getName() . '" is not browsable. No folder is currently selectable.', '', ‪FlashMessage::WARNING));
99  if (empty($PA['items'])) {
100  $PA['items'][] = [
101  $PA['row'][$PA['field']],
102  $PA['row'][$PA['field']]
103  ];
104  }
105  }
106  } else {
107  $PA['items'][] = ['', 'Please choose a FAL mount from above first.'];
108  }
109  }
110 
119  protected function ‪getSubfoldersForOptionList(‪Folder $parentFolder, $level = 0)
120  {
121  $level++;
122  // hard break on recursion
123  if ($level > 99) {
124  return [];
125  }
126  $allFolderItems = [$parentFolder];
127  $subFolders = $parentFolder->‪getSubfolders();
128  foreach ($subFolders as $subFolder) {
129  try {
130  $subFolderItems = $this->‪getSubfoldersForOptionList($subFolder, $level);
132  $subFolderItems = [];
133  }
134  $allFolderItems = array_merge($allFolderItems, $subFolderItems);
135  }
136  return $allFolderItems;
137  }
138 
145  {
146  return ‪$GLOBALS['BE_USER'];
147  }
148 }
‪TYPO3\CMS\Core\Resource\ResourceStorage\getUid
‪int getUid()
Definition: ResourceStorage.php:321
‪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:1784
‪TYPO3\CMS\Core\Resource\ResourceStorage\getRootLevelFolder
‪Folder getRootLevelFolder($respectFileMounts=true)
Definition: ResourceStorage.php:2615
‪TYPO3\CMS\Core\Resource\Service\UserFileMountService\getBackendUserAuthentication
‪BackendUserAuthentication getBackendUserAuthentication()
Definition: UserFileMountService.php:144
‪TYPO3\CMS\Core\Resource\Service
Definition: ExtractorService.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:119
‪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:290
‪TYPO3\CMS\Core\Resource\Service\UserFileMountService\renderTceformsSelectDropdown
‪renderTceformsSelectDropdown(&$PA)
Definition: UserFileMountService.php:43
‪TYPO3\CMS\Core\Resource\ResourceStorage\isBrowsable
‪bool isBrowsable()
Definition: ResourceStorage.php:393
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:37
‪TYPO3\CMS\Core\Resource\StorageRepository
Definition: StorageRepository.php:31
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Resource\ResourceStorage\getFileMounts
‪array getFileMounts()
Definition: ResourceStorage.php:576
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:122
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪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:311
‪TYPO3\CMS\Core\Resource\Exception\InsufficientFolderReadPermissionsException
Definition: InsufficientFolderReadPermissionsException.php:22