‪TYPO3CMS  ‪main
AbstractResourceBrowser.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 
18 use Psr\Http\Message\ServerRequestInterface;
35 
40 {
41  protected ?string ‪$expandFolder = null;
42  protected int ‪$currentPage = 1;
43  protected string ‪$moduleStorageIdentifier = 'file_list';
44 
45  protected ?‪FileList ‪$filelist = null;
46  protected ?string ‪$viewMode = null;
47  protected ?string ‪$displayThumbs = null;
48 
49  protected ?‪Folder ‪$selectedFolder = null;
52 
56  protected function ‪initialize(ServerRequestInterface ‪$request): void
57  {
58  parent::initialize(‪$request);
59  $this->view = $this->backendViewFactory->create($this->‪getRequest(), ['typo3/cms-filelist']);
60  $this->view->assign('initialNavigationWidth', $this->‪getBackendUser()->uc['selector']['navigation']['width'] ?? 250);
61 
62  $this->pageRenderer->loadJavaScriptModule('@typo3/backend/tree/file-storage-browser.js');
63  $this->pageRenderer->loadJavaScriptModule('@typo3/filelist/file-list-actions.js');
64  $this->pageRenderer->loadJavaScriptModule('@typo3/backend/multi-record-selection.js');
65  $this->pageRenderer->loadJavaScriptModule('@typo3/backend/global-event-handler.js');
66  }
67 
68  protected function ‪initVariables(ServerRequestInterface ‪$request): void
69  {
70  parent::initVariables(‪$request);
71 
72  $this->currentPage = (int)(‪$request->getParsedBody()['currentPage'] ?? ‪$request->getQueryParams()['currentPage'] ?? 1);
73  $this->‪expandFolder = $request->getParsedBody()['expandFolder'] ?? ‪$request->getQueryParams()['expandFolder'] ?? null;
74 
75  $this->viewMode = ‪$request->getParsedBody()['viewMode'] ?? ‪$request->getQueryParams()['viewMode'] ?? null;
76  if ($this->viewMode !== null) {
77  $this->‪getBackendUser()->pushModuleData(
78  $this->moduleStorageIdentifier,
79  array_merge($this->‪getBackendUser()->getModuleData($this->moduleStorageIdentifier) ?? [], ['viewMode' => $this->viewMode])
80  );
81  } else {
82  $this->viewMode = $this->‪getBackendUser()->getModuleData($this->moduleStorageIdentifier)['viewMode'] ?? ‪ViewMode::TILES->value;
83  }
84 
85  $this->displayThumbs = ‪$request->getParsedBody()['displayThumbs'] ?? ‪$request->getQueryParams()['displayThumbs'] ?? null;
86  if ($this->displayThumbs !== null) {
87  $this->‪getBackendUser()->pushModuleData(
88  $this->moduleStorageIdentifier,
89  array_merge($this->‪getBackendUser()->getModuleData($this->moduleStorageIdentifier) ?? [], ['displayThumbs' => $this->displayThumbs])
90  );
91  } else {
92  $this->displayThumbs = $this->‪getBackendUser()->getModuleData($this->moduleStorageIdentifier)['displayThumbs'] ?? true;
93  }
94 
95  $this->filelist = GeneralUtility::makeInstance(FileList::class, $this->‪getRequest());
96  $this->filelist->viewMode = ViewMode::tryFrom($this->viewMode) ?? ‪ViewMode::TILES;
97  $this->filelist->thumbs = (‪$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'] ?? false) && $this->displayThumbs;
98  }
99 
100  protected function ‪initSelectedFolder(): void
101  {
102  $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
103 
104  // Select folder
105  if ($this->‪expandFolder) {
106  try {
107  $this->selectedFolder = $resourceFactory->getFolderObjectFromCombinedIdentifier($this->‪expandFolder);
108  } catch (‪FolderDoesNotExistException $e) {
109  }
110  }
111 
112  if (!$this->selectedFolder) {
113  $this->selectedFolder = $resourceFactory->getDefaultStorage()?->getRootLevelFolder() ?? null;
114  }
115  }
116 
118  {
119  $viewModeItems = [];
120  $viewModeItems[] = GeneralUtility::makeInstance(DropDownRadio::class)
121  ->setActive($this->viewMode === ‪ViewMode::TILES->value)
122  ->setHref($this->‪createUri(['viewMode' => ‪ViewMode::TILES->value]))
123  ->setLabel($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.view.tiles'))
124  ->setIcon($this->iconFactory->getIcon('actions-viewmode-tiles'));
125  $viewModeItems[] = GeneralUtility::makeInstance(DropDownRadio::class)
126  ->setActive($this->viewMode === ‪ViewMode::LIST->value)
127  ->setHref($this->‪createUri(['viewMode' => ‪ViewMode::LIST->value]))
128  ->setLabel($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.view.list'))
129  ->setIcon($this->iconFactory->getIcon('actions-viewmode-list'));
130  if (!($this->‪getBackendUser()->getTSConfig()['options.']['noThumbsInEB'] ?? false)) {
131  $viewModeItems[] = GeneralUtility::makeInstance(DropdownDivider::class);
132  $viewModeItems[] = GeneralUtility::makeInstance(DropDownToggle::class)
133  ->setActive((bool)$this->displayThumbs)
134  ->setHref($this->‪createUri(['displayThumbs' => $this->displayThumbs ? 0 : 1]))
135  ->setLabel($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.view.showThumbnails'))
136  ->setIcon($this->iconFactory->getIcon('actions-image'));
137  }
138 
139  $viewModeButton = GeneralUtility::makeInstance(DropDownButton::class)
140  ->setLabel($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.view'));
141  foreach ($viewModeItems as $viewModeItem) {
143  $viewModeButton->addItem($viewModeItem);
144  }
145 
146  return $viewModeButton;
147  }
148 
153  public function ‪getUrlParameters(array $values): array
154  {
155  $values = array_replace_recursive([
156  'mode' => $this->identifier,
157  'expandFolder' => $values['identifier'] ?? $this->‪expandFolder,
158  'bparams' => $this->bparams,
159  ], $values);
160 
161  $values = array_filter($values, static function ($value) {
162  return $value !== null && trim($value) !== '';
163  });
164 
165  return $values;
166  }
167 
168  protected function ‪createUri(array $parameters = []): string
169  {
170  $parameters = $this->‪getUrlParameters($parameters);
171  return (string)$this->uriBuilder->buildUriFromRequest($this->‪getRequest(), $parameters);
172  }
173 
180  public function ‪processSessionData($data): array
181  {
182  if ($this->‪expandFolder !== null) {
183  $data['expandFolder'] = ‪$this->expandFolder;
184  ‪$store = true;
185  } else {
186  $this->‪expandFolder = $data['expandFolder'] ?? null;
187  ‪$store = false;
188  }
189  return [$data, ‪$store];
190  }
191 }
‪TYPO3\CMS\Backend\ElementBrowser\ElementBrowserInterface
Definition: ElementBrowserInterface.php:28
‪TYPO3\CMS\Scheduler\LIST
‪@ LIST
Definition: SchedulerManagementAction.php:28
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\$viewMode
‪string $viewMode
Definition: AbstractResourceBrowser.php:46
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\initSelectedFolder
‪initSelectedFolder()
Definition: AbstractResourceBrowser.php:100
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\expandFolder
‪array< int, function processSessionData( $data):array { if( $this->expandFolder !==null) { $data[ 'expandFolder']=$this-> expandFolder
Definition: AbstractResourceBrowser.php:183
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDownButton
Definition: DropDownButton.php:48
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\initialize
‪initialize(ServerRequestInterface $request)
Definition: AbstractResourceBrowser.php:56
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\$moduleStorageIdentifier
‪string $moduleStorageIdentifier
Definition: AbstractResourceBrowser.php:43
‪TYPO3\CMS\Filelist\ElementBrowser
Definition: AbstractResourceBrowser.php:16
‪TYPO3\CMS\Filelist\Matcher\Matcher
Definition: Matcher.php:24
‪TYPO3\CMS\Backend\ElementBrowser\AbstractElementBrowser
Definition: AbstractElementBrowser.php:39
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\DropDownToggle
Definition: DropDownToggle.php:39
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\createUri
‪createUri(array $parameters=[])
Definition: AbstractResourceBrowser.php:168
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\DropDownDivider
Definition: DropDownDivider.php:27
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\$expandFolder
‪string $expandFolder
Definition: AbstractResourceBrowser.php:41
‪TYPO3\CMS\Filelist\FileList
Definition: FileList.php:75
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\DropDownRadio
Definition: DropDownRadio.php:54
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\DropDownItemInterface
Definition: DropDownItemInterface.php:19
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:37
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Core\Resource\Exception\FolderDoesNotExistException
Definition: FolderDoesNotExistException.php:22
‪TYPO3\CMS\Backend\ElementBrowser\AbstractElementBrowser\getLanguageService
‪getLanguageService()
Definition: AbstractElementBrowser.php:157
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\initVariables
‪initVariables(ServerRequestInterface $request)
Definition: AbstractResourceBrowser.php:68
‪TYPO3\CMS\Backend\ElementBrowser\ElementBrowserInterface\processSessionData
‪array[] processSessionData($data)
‪TYPO3\CMS\Backend\ElementBrowser\AbstractElementBrowser\getRequest
‪getRequest()
Definition: AbstractElementBrowser.php:152
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\$selectedFolder
‪Folder $selectedFolder
Definition: AbstractResourceBrowser.php:49
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\getViewModeButton
‪getViewModeButton()
Definition: AbstractResourceBrowser.php:117
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\$store
‪$store
Definition: AbstractResourceBrowser.php:184
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\$resourceDisplayMatcher
‪Matcher $resourceDisplayMatcher
Definition: AbstractResourceBrowser.php:50
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\$resourceSelectableMatcher
‪Matcher $resourceSelectableMatcher
Definition: AbstractResourceBrowser.php:51
‪TYPO3\CMS\Filelist\Type\TILES
‪@ TILES
Definition: ViewMode.php:26
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\getUrlParameters
‪string[] getUrlParameters(array $values)
Definition: AbstractResourceBrowser.php:153
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\$filelist
‪FileList $filelist
Definition: AbstractResourceBrowser.php:45
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Filelist\Type\ViewMode
‪ViewMode
Definition: ViewMode.php:24
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\$currentPage
‪int $currentPage
Definition: AbstractResourceBrowser.php:42
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser
Definition: AbstractResourceBrowser.php:40
‪TYPO3\CMS\Backend\ElementBrowser\AbstractElementBrowser\$request
‪ServerRequestInterface $request
Definition: AbstractElementBrowser.php:65
‪TYPO3\CMS\Backend\ElementBrowser\AbstractElementBrowser\getBackendUser
‪getBackendUser()
Definition: AbstractElementBrowser.php:162
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\$displayThumbs
‪string $displayThumbs
Definition: AbstractResourceBrowser.php:47
‪TYPO3\CMS\Backend\Template\Components\Buttons\ButtonInterface
Definition: ButtonInterface.php:22