TYPO3 CMS  TYPO3_6-2
UserFileMountService.php
Go to the documentation of this file.
1 <?php
3 
18 
29 
39  public function renderTceformsSelectDropdown(&$PA, &$tceformsObj) {
40  // If working for sys_filemounts table
41  $storageUid = (int)$PA['row']['base'];
42  if (!$storageUid) {
43  // If working for sys_file_collection table
44  $storageUid = (int)$PA['row']['storage'];
45  }
46  if ($storageUid > 0) {
48  $storageRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository');
50  $storage = $storageRepository->findByUid($storageUid);
51  if ($storage === NULL) {
53  $flashMessageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
54  $queue = $flashMessageService->getMessageQueueByIdentifier();
55  $queue->enqueue(new FlashMessage('Storage #' . $storageUid . ' does not exist. No folder is currently selectable.', '', FlashMessage::ERROR));
56  if (!count($PA['items'])) {
57  $PA['items'][] = array(
58  $PA['row'][$PA['field']],
59  $PA['row'][$PA['field']]
60  );
61  }
62  } elseif ($storage->isBrowsable()) {
63  $rootLevelFolders = array();
64 
65  $fileMounts = $storage->getFileMounts();
66  if (!empty($fileMounts)) {
67  foreach ($fileMounts as $fileMountInfo) {
68  $rootLevelFolders[] = $fileMountInfo['folder'];
69  }
70  } else {
71  $rootLevelFolders[] = $storage->getRootLevelFolder();
72  }
73 
74  foreach ($rootLevelFolders as $rootLevelFolder) {
75  $folderItems = $this->getSubfoldersForOptionList($rootLevelFolder);
76  foreach ($folderItems as $item) {
77  $PA['items'][] = array(
78  $item->getIdentifier(),
79  $item->getIdentifier()
80  );
81  }
82  }
83  } else {
85  $flashMessageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
86  $queue = $flashMessageService->getMessageQueueByIdentifier();
87  $queue->enqueue(new FlashMessage('Storage "' . $storage->getName() . '" is not browsable. No folder is currently selectable.', '', FlashMessage::WARNING));
88  if (!count($PA['items'])) {
89  $PA['items'][] = array(
90  $PA['row'][$PA['field']],
91  $PA['row'][$PA['field']]
92  );
93  }
94  }
95  } else {
96  $PA['items'][] = array('', 'Please choose a FAL mount from above first.');
97  }
98  }
99 
108  protected function getSubfoldersForOptionList(\TYPO3\CMS\Core\Resource\Folder $parentFolder, $level = 0) {
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 
127 }
getSubfoldersForOptionList(\TYPO3\CMS\Core\Resource\Folder $parentFolder, $level=0)