TYPO3 CMS  TYPO3_8-7
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  },
47  $this->getBackendUserAuthentication()->getFileStorages()
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 }
static makeInstance($className,... $constructorArguments)
getSubfolders($start=0, $numberOfItems=0, $filterMode=self::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, $recursive=false)
Definition: Folder.php:272
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']