‪TYPO3CMS  10.4
FolderBrowser.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 
25 
31 {
40  protected ‪$expandFolder;
41 
45  protected function ‪initialize()
46  {
47  parent::initialize();
48  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Recordlist/BrowseFolders');
49  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LegacyTree', 'function() {
50  DragDrop.table = "folders";
51  Tree.registerDragDropHandlers();
52  }');
53  }
54 
58  protected function ‪initVariables()
59  {
60  parent::initVariables();
61  $this->expandFolder = GeneralUtility::_GP('expandFolder');
62  }
63 
70  public function ‪processSessionData($data)
71  {
72  if ($this->expandFolder !== null) {
73  $data['expandFolder'] = ‪$this->expandFolder;
74  $store = true;
75  } else {
76  $this->expandFolder = $data['expandFolder'];
77  $store = false;
78  }
79  return [$data, $store];
80  }
81 
85  public function ‪render()
86  {
87  $selectedFolder = null;
88  if ($this->expandFolder) {
89  $selectedFolder = GeneralUtility::makeInstance(ResourceFactory::class)->getFolderObjectFromCombinedIdentifier($this->expandFolder);
90  }
91 
92  // Create folder tree:
93  $folderTree = GeneralUtility::makeInstance(ElementBrowserFolderTreeView::class);
94  $folderTree->setLinkParameterProvider($this);
95  $tree = $folderTree->getBrowsableTree();
96 
97  $folders = '';
98  if ($selectedFolder) {
99  $folders = $this->‪renderFolders($selectedFolder);
100  }
101  if ($selectedFolder) {
102  $folders .= GeneralUtility::makeInstance(FolderUtilityRenderer::class, $this)->createFolder($selectedFolder);
103  }
104 
105  $this->‪setBodyTagParameters();
106  $this->moduleTemplate->setTitle($this->‪getLanguageService()->getLL('folderSelector'));
107  $view = $this->moduleTemplate->getView();
108  $view->assignMultiple([
109  'treeEnabled' => true,
110  'tree' => $tree,
111  'content' => $folders
112  ]);
113  return $this->moduleTemplate->renderContent();
114  }
115 
120  protected function ‪renderFolders(‪Folder $parentFolder)
121  {
122  if (!$parentFolder->‪checkActionPermission('read')) {
123  return '';
124  }
125  $content = '';
126  $lang = $this->‪getLanguageService();
127  $folders = $parentFolder->‪getSubfolders();
128  $folderIdentifier = $parentFolder->‪getCombinedIdentifier();
129 
130  // Create headline (showing number of folders):
131  $content .= '<h3>' . sprintf(htmlspecialchars($lang->getLL('folders')) . ' (%s):', count($folders)) . '</h3>';
132 
133  $titleLength = (int)$this->‪getBackendUser()->uc['titleLen'];
134  // Create the header of current folder:
135  $folderIcon = '<a href="#" data-folder-id="' . htmlspecialchars($folderIdentifier) . '" data-close="1">';
136  $folderIcon .= $this->iconFactory->getIcon('apps-filetree-folder-default', ‪Icon::SIZE_SMALL);
137  $folderIcon .= htmlspecialchars(GeneralUtility::fixed_lgd_cs($parentFolder->‪getName(), $titleLength));
138  $folderIcon .= '</a>';
139  $content .= $folderIcon . '<br />';
140 
141  $lines = [];
142  // Traverse the folder list:
143  foreach ($folders as $subFolder) {
144  $subFolderIdentifier = $subFolder->getCombinedIdentifier();
145  // Create folder icon:
146  $icon = '<span style="width: 16px; height: 16px; display: inline-block;"></span>';
147  $icon .= '<span title="' . htmlspecialchars($subFolder->getName()) . '">' . $this->iconFactory->getIcon('apps-filetree-folder-default', ‪Icon::SIZE_SMALL) . '</span>';
148  // Create links for adding the folder:
149  $aTag = '<a href="#" data-folder-id="' . htmlspecialchars($subFolderIdentifier) . '" data-close="0">';
150  $aTag_alt = '<a href="#" data-folder-id="' . htmlspecialchars($subFolderIdentifier) . '" data-close="1">';
151  if (strpos($subFolderIdentifier, ',') !== false || strpos($subFolderIdentifier, '|') !== false) {
152  // In case an invalid character is in the filepath, display error message:
153  $errorMessage = sprintf(htmlspecialchars($lang->getLL('invalidChar')), ', |');
154  $aTag = '<a href="#" class="t3js-folderIdError" data-message="' . $errorMessage . '">';
155  }
156  $aTag_e = '</a>';
157  // Combine icon and folderpath:
158  $foldernameAndIcon = $aTag_alt . $icon . htmlspecialchars(GeneralUtility::fixed_lgd_cs($subFolder->getName(), $titleLength)) . $aTag_e;
159  $lines[] = '
160  <tr>
161  <td class="nowrap">' . $foldernameAndIcon . '&nbsp;</td>
162  <td>' . $aTag . '<span title="' . htmlspecialchars($lang->getLL('addToList')) . '">' . $this->iconFactory->getIcon('actions-add', ‪Icon::SIZE_SMALL)->render() . '</span>' . $aTag_e . '</td>
163  <td>&nbsp;</td>
164  </tr>';
165  $lines[] = '
166  <tr>
167  <td colspan="3"><span style="width: 1px; height: 3px; display: inline-block;"></span></td>
168  </tr>';
169  }
170  // Wrap all the rows in table tags:
171  $content .= '
172 
173  <!--
174  Folder listing
175  -->
176  <table border="0" cellpadding="0" cellspacing="1" id="typo3-folderList">
177  ' . implode('', $lines) . '
178  </table>';
179 
180  return $content;
181  }
182 
186  protected function ‪getBodyTagAttributes()
187  {
188  return [
189  'data-mode' => 'folder'
190  ];
191  }
192 
197  public function ‪getUrlParameters(array $values)
198  {
199  return [
200  'mode' => 'folder',
201  'expandFolder' => $values['identifier'] ?? ‪$this->expandFolder,
202  'bparams' => ‪$this->bparams
203  ];
204  }
205 
210  public function ‪isCurrentlySelectedItem(array $values)
211  {
212  return false;
213  }
214 
220  public function ‪getScriptUrl()
221  {
222  return ‪$this->thisScript;
223  }
224 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser\$expandFolder
‪string null $expandFolder
Definition: FolderBrowser.php:39
‪TYPO3\CMS\Recordlist\Browser\ElementBrowserInterface
Definition: ElementBrowserInterface.php:19
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser\$thisScript
‪string $thisScript
Definition: AbstractElementBrowser.php:46
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: AbstractElementBrowser.php:165
‪TYPO3\CMS\Backend\Tree\View\ElementBrowserFolderTreeView
Definition: ElementBrowserFolderTreeView.php:31
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser
Definition: FolderBrowser.php:31
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser\isCurrentlySelectedItem
‪bool isCurrentlySelectedItem(array $values)
Definition: FolderBrowser.php:209
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser\initialize
‪initialize()
Definition: FolderBrowser.php:44
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser\initVariables
‪initVariables()
Definition: FolderBrowser.php:57
‪TYPO3\CMS\Core\Resource\Folder\getName
‪string getName()
Definition: Folder.php:94
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser\renderFolders
‪string renderFolders(Folder $parentFolder)
Definition: FolderBrowser.php:119
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser\getLanguageService
‪array< string, getBodyTagAttributes();protected array< string, function getBParamDataAttributes() {[ $fieldRef, $rteParams, $rteConfig,, $irreObjectId]=explode('|', $this->bparams);return['data-this-script-url'=> strpos( $this->thisScript, '?')===false ? $this-> LanguageService function getLanguageService()
Definition: AbstractElementBrowser.php:157
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser\render
‪string render()
Definition: FolderBrowser.php:84
‪TYPO3\CMS\Core\Resource\Folder\getSubfolders
‪Folder[] getSubfolders($start=0, $numberOfItems=0, $filterMode=self::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, $recursive=false)
Definition: Folder.php:290
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:37
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser
Definition: AbstractElementBrowser.php:33
‪TYPO3\CMS\Core\Resource\Folder\checkActionPermission
‪bool checkActionPermission($action)
Definition: Folder.php:423
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser\getScriptUrl
‪string getScriptUrl()
Definition: FolderBrowser.php:219
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser\getUrlParameters
‪string[] getUrlParameters(array $values)
Definition: FolderBrowser.php:196
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser\getBodyTagAttributes
‪string[] getBodyTagAttributes()
Definition: FolderBrowser.php:185
‪TYPO3\CMS\Recordlist\View\FolderUtilityRenderer
Definition: FolderUtilityRenderer.php:33
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser\$bparams
‪string $bparams
Definition: AbstractElementBrowser.php:69
‪TYPO3\CMS\Core\Resource\Folder\getCombinedIdentifier
‪string getCombinedIdentifier()
Definition: Folder.php:181
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser\setBodyTagParameters
‪setBodyTagParameters()
Definition: AbstractElementBrowser.php:118
‪TYPO3\CMS\Recordlist\Browser
Definition: AbstractElementBrowser.php:16
‪TYPO3\CMS\Recordlist\Browser\FolderBrowser\processSessionData
‪array[] processSessionData($data)
Definition: FolderBrowser.php:69