TYPO3  7.6
UserFileMountService.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Resource\Service;
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 
19 
28 {
37  public function renderTceformsSelectDropdown(&$PA)
38  {
39  // If working for sys_filemounts table
40  $storageUid = (int)$PA['row']['base'][0];
41  if (!$storageUid) {
42  // If working for sys_file_collection table
43  $storageUid = (int)$PA['row']['storage'];
44  }
45  if ($storageUid > 0) {
47  $storageRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class);
49  $storage = $storageRepository->findByUid($storageUid);
50  if ($storage === null) {
52  $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
53  $queue = $flashMessageService->getMessageQueueByIdentifier();
54  $queue->enqueue(new FlashMessage('Storage #' . $storageUid . ' does not exist. No folder is currently selectable.', '', FlashMessage::ERROR));
55  if (empty($PA['items'])) {
56  $PA['items'][] = array(
57  $PA['row'][$PA['field']],
58  $PA['row'][$PA['field']]
59  );
60  }
61  } elseif ($storage->isBrowsable()) {
62  $rootLevelFolders = array();
63 
64  $fileMounts = $storage->getFileMounts();
65  if (!empty($fileMounts)) {
66  foreach ($fileMounts as $fileMountInfo) {
67  $rootLevelFolders[] = $fileMountInfo['folder'];
68  }
69  } else {
70  $rootLevelFolders[] = $storage->getRootLevelFolder();
71  }
72 
73  foreach ($rootLevelFolders as $rootLevelFolder) {
74  $folderItems = $this->getSubfoldersForOptionList($rootLevelFolder);
75  foreach ($folderItems as $item) {
76  $PA['items'][] = array(
77  $item->getIdentifier(),
78  $item->getIdentifier()
79  );
80  }
81  }
82  } else {
84  $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
85  $queue = $flashMessageService->getMessageQueueByIdentifier();
86  $queue->enqueue(new FlashMessage('Storage "' . $storage->getName() . '" is not browsable. No folder is currently selectable.', '', FlashMessage::WARNING));
87  if (empty($PA['items'])) {
88  $PA['items'][] = array(
89  $PA['row'][$PA['field']],
90  $PA['row'][$PA['field']]
91  );
92  }
93  }
94  } else {
95  $PA['items'][] = array('', 'Please choose a FAL mount from above first.');
96  }
97  }
98 
107  protected function getSubfoldersForOptionList(\TYPO3\CMS\Core\Resource\Folder $parentFolder, $level = 0)
108  {
109  $level++;
110  // hard break on recursion
111  if ($level > 99) {
112  return array();
113  }
114  $allFolderItems = array($parentFolder);
115  $subFolders = $parentFolder->getSubfolders();
116  foreach ($subFolders as $subFolder) {
117  try {
118  $subFolderItems = $this->getSubfoldersForOptionList($subFolder, $level);
119  } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderReadPermissionsException $e) {
120  $subFolderItems = array();
121  }
122  $allFolderItems = array_merge($allFolderItems, $subFolderItems);
123  }
124  return $allFolderItems;
125  }
126 }