‪TYPO3CMS  ‪main
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 
27 
38 {
39  public function ‪__construct()
40  {
41  trigger_error('Class ' . __CLASS__ . ' will be removed with TYPO3 v13.0.', E_USER_DEPRECATED);
42  }
43 
51  public function ‪renderTceformsSelectDropdown(&$PA)
52  {
53  $allowedStorageIds = array_map(
54  static function (‪ResourceStorage $storage) {
55  return $storage->‪getUid();
56  },
57  $this->‪getBackendUserAuthentication()->getFileStorages()
58  );
59  $storageUid = (int)($PA['row']['storage'][0] ?? 0);
60  if ($storageUid > 0 && in_array($storageUid, $allowedStorageIds, true)) {
61  $storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
63  $storage = $storageRepository->findByUid($storageUid);
64  if ($storage === null) {
65  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
66  $queue = $flashMessageService->getMessageQueueByIdentifier();
67  $queue->enqueue(new ‪FlashMessage('Storage #' . $storageUid . ' does not exist. No folder is currently selectable.', '', ContextualFeedbackSeverity::ERROR));
68  if (empty($PA['items'])) {
69  $PA['items'][] = [
70  $PA['row'][$PA['field']],
71  $PA['row'][$PA['field']],
72  ];
73  }
74  } elseif ($storage->‪isBrowsable()) {
75  $rootLevelFolders = [];
76 
77  $fileMounts = $storage->‪getFileMounts();
78  if (!empty($fileMounts)) {
79  foreach ($fileMounts as $fileMountInfo) {
80  $rootLevelFolders[] = $fileMountInfo['folder'];
81  }
82  } else {
83  $rootLevelFolders[] = $storage->‪getRootLevelFolder();
84  }
85 
86  foreach ($rootLevelFolders as $rootLevelFolder) {
87  $folderItems = $this->‪getSubfoldersForOptionList($rootLevelFolder);
88  foreach ($folderItems as $item) {
89  $PA['items'][] = [
90  $item->getIdentifier(),
91  $item->getIdentifier(),
92  ];
93  }
94  }
95  } 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.', '', ContextualFeedbackSeverity::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 
118  protected function ‪getSubfoldersForOptionList(‪Folder $parentFolder, $level = 0)
119  {
120  $level++;
121  // hard break on recursion
122  if ($level > 99) {
123  return [];
124  }
125  $allFolderItems = [$parentFolder];
126  $subFolders = $parentFolder->getSubfolders();
127  foreach ($subFolders as $subFolder) {
128  try {
129  $subFolderItems = $this->‪getSubfoldersForOptionList($subFolder, $level);
131  $subFolderItems = [];
132  }
133  $allFolderItems = array_merge($allFolderItems, $subFolderItems);
134  }
135  return $allFolderItems;
136  }
137 
139  {
140  return ‪$GLOBALS['BE_USER'];
141  }
142 }
‪TYPO3\CMS\Core\Resource\ResourceStorage\getUid
‪int getUid()
Definition: ResourceStorage.php:328
‪TYPO3\CMS\Core\Resource\Service\UserFileMountService\getBackendUserAuthentication
‪getBackendUserAuthentication()
Definition: UserFileMountService.php:138
‪TYPO3\CMS\Core\Resource\Service\UserFileMountService
Definition: UserFileMountService.php:38
‪TYPO3\CMS\Core\Resource\ResourceStorage\getRootLevelFolder
‪Folder getRootLevelFolder($respectFileMounts=true)
Definition: ResourceStorage.php:2566
‪TYPO3\CMS\Core\Type\ContextualFeedbackSeverity
‪ContextualFeedbackSeverity
Definition: ContextualFeedbackSeverity.php:25
‪TYPO3\CMS\Core\Resource\Service
Definition: ConfigurationService.php:18
‪TYPO3\CMS\Core\Resource\Service\UserFileMountService\getSubfoldersForOptionList
‪Folder[] getSubfoldersForOptionList(Folder $parentFolder, $level=0)
Definition: UserFileMountService.php:118
‪TYPO3\CMS\Core\Resource\Service\UserFileMountService\renderTceformsSelectDropdown
‪renderTceformsSelectDropdown(&$PA)
Definition: UserFileMountService.php:51
‪TYPO3\CMS\Core\Resource\ResourceStorage\isBrowsable
‪bool isBrowsable()
Definition: ResourceStorage.php:400
‪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:66
‪TYPO3\CMS\Core\Resource\ResourceStorage\getFileMounts
‪array getFileMounts()
Definition: ResourceStorage.php:581
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:127
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:27
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Resource\Service\UserFileMountService\__construct
‪__construct()
Definition: UserFileMountService.php:39
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:27
‪TYPO3\CMS\Core\Resource\ResourceStorage\getName
‪string getName()
Definition: ResourceStorage.php:318
‪TYPO3\CMS\Core\Resource\Exception\InsufficientFolderReadPermissionsException
Definition: InsufficientFolderReadPermissionsException.php:22