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