‪TYPO3CMS  ‪main
AbstractResourceBrowser.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ServerRequestInterface;
37 
42 {
43  protected ?string ‪$expandFolder = null;
44  protected int ‪$currentPage = 1;
45  protected string ‪$moduleStorageIdentifier = 'file_list';
46 
47  protected ?‪FileList ‪$filelist = null;
48  protected ?‪ViewMode ‪$viewMode = null;
49  protected bool ‪$displayThumbs = true;
50 
51  protected ?‪Folder ‪$selectedFolder = null;
54 
58  protected function ‪initialize(ServerRequestInterface ‪$request): void
59  {
60  parent::initialize(‪$request);
61  $this->view = $this->backendViewFactory->create($this->‪getRequest(), ['typo3/cms-filelist']);
62  $this->view->assign('initialNavigationWidth', $this->‪getBackendUser()->uc['selector']['navigation']['width'] ?? 250);
63 
64  $this->pageRenderer->loadJavaScriptModule('@typo3/backend/tree/file-storage-browser.js');
65  $this->pageRenderer->loadJavaScriptModule('@typo3/filelist/file-list-actions.js');
66  $this->pageRenderer->loadJavaScriptModule('@typo3/backend/multi-record-selection.js');
67  $this->pageRenderer->loadJavaScriptModule('@typo3/backend/global-event-handler.js');
68  }
69 
70  protected function ‪initVariables(ServerRequestInterface ‪$request): void
71  {
72  parent::initVariables(‪$request);
73 
74  $this->currentPage = (int)(‪$request->getParsedBody()['currentPage'] ?? ‪$request->getQueryParams()['currentPage'] ?? 1);
75  $this->‪expandFolder = $request->getParsedBody()['expandFolder'] ?? ‪$request->getQueryParams()['expandFolder'] ?? null;
76 
77  $this->viewMode = ‪ViewMode::tryFrom(‪$request->getParsedBody()['viewMode'] ?? ‪$request->getQueryParams()['viewMode'] ?? '');
78  if ($this->viewMode !== null) {
79  $this->‪getBackendUser()->pushModuleData(
80  $this->moduleStorageIdentifier,
81  array_merge($this->‪getBackendUser()->getModuleData($this->moduleStorageIdentifier) ?? [], ['viewMode' => $this->viewMode->value])
82  );
83  } else {
84  $this->viewMode = ‪ViewMode::tryFrom($this->‪getBackendUser()->getModuleData($this->moduleStorageIdentifier)['viewMode'] ?? '')
85  ?? ‪ViewMode::tryFrom($this->‪getBackendUser()->getTSConfig()['options.']['defaultResourcesViewMode'] ?? '')
87  }
88 
89  ‪$displayThumbs = ‪$request->getParsedBody()['displayThumbs'] ?? ‪$request->getQueryParams()['displayThumbs'] ?? null;
90  if (‪$displayThumbs !== null) {
91  $this->displayThumbs = (bool)‪$displayThumbs;
92  $this->‪getBackendUser()->pushModuleData(
93  $this->moduleStorageIdentifier,
94  array_merge($this->‪getBackendUser()->getModuleData($this->moduleStorageIdentifier) ?? [], ['displayThumbs' => $this->displayThumbs])
95  );
96  } else {
97  $this->displayThumbs = (bool)($this->‪getBackendUser()->getModuleData($this->moduleStorageIdentifier)['displayThumbs'] ?? true);
98  }
99 
100  $this->filelist = GeneralUtility::makeInstance(FileList::class, $this->‪getRequest());
101  $this->filelist->viewMode = ‪$this->viewMode;
102  $this->filelist->thumbs = (‪$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'] ?? false) && $this->displayThumbs;
103  }
104 
105  protected function ‪initSelectedFolder(): void
106  {
107  $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
108 
109  // Select folder
110  if ($this->‪expandFolder) {
111  try {
112  $this->selectedFolder = $resourceFactory->getFolderObjectFromCombinedIdentifier($this->‪expandFolder);
113  } catch (‪FolderDoesNotExistException $e) {
114  }
115  }
116 
117  if (!$this->selectedFolder) {
118  $this->selectedFolder = $resourceFactory->getDefaultStorage()?->getRootLevelFolder();
119  }
120  }
121 
123  {
124  $viewModeItems = [];
125  $viewModeItems[] = GeneralUtility::makeInstance(DropDownRadio::class)
126  ->setActive($this->viewMode === ‪ViewMode::TILES)
127  ->setHref($this->‪createUri(['viewMode' => ‪ViewMode::TILES->value]))
128  ->setLabel($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.view.tiles'))
129  ->setIcon($this->iconFactory->getIcon('actions-viewmode-tiles'));
130  $viewModeItems[] = GeneralUtility::makeInstance(DropDownRadio::class)
131  ->setActive($this->viewMode === ‪ViewMode::LIST)
132  ->setHref($this->‪createUri(['viewMode' => ‪ViewMode::LIST->value]))
133  ->setLabel($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.view.list'))
134  ->setIcon($this->iconFactory->getIcon('actions-viewmode-list'));
135  if (!($this->‪getBackendUser()->getTSConfig()['options.']['noThumbsInEB'] ?? false)) {
136  $viewModeItems[] = GeneralUtility::makeInstance(DropDownDivider::class);
137  $viewModeItems[] = GeneralUtility::makeInstance(DropDownToggle::class)
138  ->setActive($this->displayThumbs)
139  ->setHref($this->‪createUri(['displayThumbs' => $this->displayThumbs ? 0 : 1]))
140  ->setLabel($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.view.showThumbnails'))
141  ->setIcon($this->iconFactory->getIcon('actions-image'));
142  }
143 
144  $viewModeButton = GeneralUtility::makeInstance(DropDownButton::class)
145  ->setLabel($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.view'));
146  foreach ($viewModeItems as $viewModeItem) {
148  $viewModeButton->addItem($viewModeItem);
149  }
150 
151  return $viewModeButton;
152  }
153 
158  public function ‪getUrlParameters(array $values): array
159  {
160  $values = array_replace_recursive([
161  'mode' => $this->identifier,
162  'expandFolder' => $values['identifier'] ?? $this->‪expandFolder,
163  'bparams' => $this->bparams,
164  ], $values);
165 
166  return array_filter($values, static function ($value) {
167  return $value !== null && trim((string)$value) !== '';
168  });
169  }
170 
171  protected function ‪createUri(array $parameters = []): string
172  {
173  $parameters = $this->‪getUrlParameters($parameters);
174  return (string)$this->uriBuilder->buildUriFromRequest($this->‪getRequest(), $parameters);
175  }
176 
183  public function ‪processSessionData($data): array
184  {
185  if ($this->‪expandFolder !== null) {
186  $data['expandFolder'] = ‪$this->expandFolder;
187  ‪$store = true;
188  } else {
189  $this->‪expandFolder = $data['expandFolder'] ?? null;
190  ‪$store = false;
191  }
192  return [$data, ‪$store];
193  }
194 }
‪TYPO3\CMS\Backend\ElementBrowser\ElementBrowserInterface
Definition: ElementBrowserInterface.php:28
‪TYPO3\CMS\Scheduler\LIST
‪@ LIST
Definition: SchedulerManagementAction.php:28
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\initSelectedFolder
‪initSelectedFolder()
Definition: AbstractResourceBrowser.php:105
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\expandFolder
‪array< int, function processSessionData( $data):array { if( $this->expandFolder !==null) { $data[ 'expandFolder']=$this-> expandFolder
Definition: AbstractResourceBrowser.php:186
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDownButton
Definition: DropDownButton.php:48
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\initialize
‪initialize(ServerRequestInterface $request)
Definition: AbstractResourceBrowser.php:58
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\$moduleStorageIdentifier
‪string $moduleStorageIdentifier
Definition: AbstractResourceBrowser.php:45
‪TYPO3\CMS\Filelist\ElementBrowser
Definition: AbstractResourceBrowser.php:18
‪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\Frontend\Content\tryFrom
‪@ tryFrom
Definition: ContentSlideMode.php:27
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\createUri
‪createUri(array $parameters=[])
Definition: AbstractResourceBrowser.php:171
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\DropDownDivider
Definition: DropDownDivider.php:27
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\$expandFolder
‪string $expandFolder
Definition: AbstractResourceBrowser.php:43
‪TYPO3\CMS\Filelist\FileList
Definition: FileList.php:74
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\DropDownRadio
Definition: DropDownRadio.php:54
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\$displayThumbs
‪bool $displayThumbs
Definition: AbstractResourceBrowser.php:49
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDown\DropDownItemInterface
Definition: DropDownItemInterface.php:19
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:38
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:42
‪TYPO3\CMS\Core\Resource\Exception\FolderDoesNotExistException
Definition: FolderDoesNotExistException.php:21
‪TYPO3\CMS\Backend\ElementBrowser\AbstractElementBrowser\getLanguageService
‪getLanguageService()
Definition: AbstractElementBrowser.php:156
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\initVariables
‪initVariables(ServerRequestInterface $request)
Definition: AbstractResourceBrowser.php:70
‪TYPO3\CMS\Backend\ElementBrowser\ElementBrowserInterface\processSessionData
‪array[] processSessionData($data)
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\$viewMode
‪ViewMode $viewMode
Definition: AbstractResourceBrowser.php:48
‪TYPO3\CMS\Backend\ElementBrowser\AbstractElementBrowser\getRequest
‪getRequest()
Definition: AbstractElementBrowser.php:151
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\$selectedFolder
‪Folder $selectedFolder
Definition: AbstractResourceBrowser.php:51
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\getViewModeButton
‪getViewModeButton()
Definition: AbstractResourceBrowser.php:122
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\$store
‪$store
Definition: AbstractResourceBrowser.php:187
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\$resourceDisplayMatcher
‪Matcher $resourceDisplayMatcher
Definition: AbstractResourceBrowser.php:52
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\$resourceSelectableMatcher
‪Matcher $resourceSelectableMatcher
Definition: AbstractResourceBrowser.php:53
‪TYPO3\CMS\Filelist\Type\TILES
‪@ TILES
Definition: ViewMode.php:26
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\getUrlParameters
‪string[] getUrlParameters(array $values)
Definition: AbstractResourceBrowser.php:158
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\$filelist
‪FileList $filelist
Definition: AbstractResourceBrowser.php:47
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Filelist\Type\ViewMode
‪ViewMode
Definition: ViewMode.php:24
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\$currentPage
‪int $currentPage
Definition: AbstractResourceBrowser.php:44
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser
Definition: AbstractResourceBrowser.php:42
‪TYPO3\CMS\Backend\ElementBrowser\AbstractElementBrowser\$request
‪ServerRequestInterface $request
Definition: AbstractElementBrowser.php:65
‪TYPO3\CMS\Backend\ElementBrowser\AbstractElementBrowser\getBackendUser
‪getBackendUser()
Definition: AbstractElementBrowser.php:161
‪TYPO3\CMS\Backend\Template\Components\Buttons\ButtonInterface
Definition: ButtonInterface.php:22