TYPO3 CMS  TYPO3_7-6
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 
20 
29 {
37  public function renderTceformsSelectDropdown(&$PA)
38  {
39  $allowedStorageIds = array_map(
40  function (\TYPO3\CMS\Core\Resource\ResourceStorage $storage) {
41  return $storage->getUid();
42  },
43  $this->getBackendUserAuthentication()->getFileStorages()
44  );
45  // If working for sys_filemounts table
46  $storageUid = (int)$PA['row']['base'][0];
47  if (!$storageUid) {
48  // If working for sys_file_collection table
49  $storageUid = (int)$PA['row']['storage'][0];
50  }
51  if ($storageUid > 0 && in_array($storageUid, $allowedStorageIds, true)) {
53  $storageRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class);
55  $storage = $storageRepository->findByUid($storageUid);
56  if ($storage === null) {
58  $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
59  $queue = $flashMessageService->getMessageQueueByIdentifier();
60  $queue->enqueue(new FlashMessage('Storage #' . $storageUid . ' does not exist. No folder is currently selectable.', '', FlashMessage::ERROR));
61  if (empty($PA['items'])) {
62  $PA['items'][] = [
63  $PA['row'][$PA['field']],
64  $PA['row'][$PA['field']]
65  ];
66  }
67  } elseif ($storage->isBrowsable()) {
68  $rootLevelFolders = [];
69 
70  $fileMounts = $storage->getFileMounts();
71  if (!empty($fileMounts)) {
72  foreach ($fileMounts as $fileMountInfo) {
73  $rootLevelFolders[] = $fileMountInfo['folder'];
74  }
75  } else {
76  $rootLevelFolders[] = $storage->getRootLevelFolder();
77  }
78 
79  foreach ($rootLevelFolders as $rootLevelFolder) {
80  $folderItems = $this->getSubfoldersForOptionList($rootLevelFolder);
81  foreach ($folderItems as $item) {
82  $PA['items'][] = [
83  $item->getIdentifier(),
84  $item->getIdentifier()
85  ];
86  }
87  }
88  } else {
90  $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
91  $queue = $flashMessageService->getMessageQueueByIdentifier();
92  $queue->enqueue(new FlashMessage('Storage "' . $storage->getName() . '" is not browsable. No folder is currently selectable.', '', FlashMessage::WARNING));
93  if (empty($PA['items'])) {
94  $PA['items'][] = [
95  $PA['row'][$PA['field']],
96  $PA['row'][$PA['field']]
97  ];
98  }
99  }
100  } else {
101  $PA['items'][] = ['', 'Please choose a FAL mount from above first.'];
102  }
103  }
104 
113  protected function getSubfoldersForOptionList(\TYPO3\CMS\Core\Resource\Folder $parentFolder, $level = 0)
114  {
115  $level++;
116  // hard break on recursion
117  if ($level > 99) {
118  return [];
119  }
120  $allFolderItems = [$parentFolder];
121  $subFolders = $parentFolder->getSubfolders();
122  foreach ($subFolders as $subFolder) {
123  try {
124  $subFolderItems = $this->getSubfoldersForOptionList($subFolder, $level);
125  } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderReadPermissionsException $e) {
126  $subFolderItems = [];
127  }
128  $allFolderItems = array_merge($allFolderItems, $subFolderItems);
129  }
130  return $allFolderItems;
131  }
132 
138  protected function getBackendUserAuthentication()
139  {
140  return $GLOBALS['BE_USER'];
141  }
142 }
getSubfoldersForOptionList(\TYPO3\CMS\Core\Resource\Folder $parentFolder, $level=0)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']