‪TYPO3CMS  ‪main
FolderBrowser.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;
22 use TYPO3\CMS\Core\Imaging\IconSize;
29 
36 {
37  public const ‪IDENTIFIER = 'folder';
38  protected string ‪$identifier = ‪self::IDENTIFIER;
39 
40  protected function ‪initialize(ServerRequestInterface ‪$request): void
41  {
42  parent::initialize(‪$request);
43  $this->pageRenderer->loadJavaScriptModule('@typo3/filelist/browse-folders.js');
44  }
45 
46  protected function ‪initVariables(ServerRequestInterface ‪$request): void
47  {
48  parent::initVariables(‪$request);
49  $this->resourceDisplayMatcher = GeneralUtility::makeInstance(Matcher::class);
50  $this->resourceDisplayMatcher->addMatcher(GeneralUtility::makeInstance(ResourceFolderTypeMatcher::class));
51  $this->resourceSelectableMatcher = GeneralUtility::makeInstance(Matcher::class);
52  $this->resourceSelectableMatcher->addMatcher(GeneralUtility::makeInstance(ResourceFolderTypeMatcher::class));
53  }
54 
55  public function ‪render(): string
56  {
57  $this->‪initSelectedFolder();
58  $contentHtml = '';
59 
60  if ($this->selectedFolder instanceof ‪Folder) {
61  $markup = [];
62 
63  // Create the filelist header bar
64  $markup[] = '<div class="row justify-content-between mb-2">';
65  $markup[] = ' <div class="col-auto">';
66  $markup[] = ' <div class="hidden t3js-multi-record-selection-actions">';
67  $markup[] = ' <strong>' . htmlspecialchars($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.selection')) . '</strong>';
68  $markup[] = ' <button type="button" class="btn btn-default btn-sm" data-multi-record-selection-action="import" title="' . htmlspecialchars($this->‪getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_browse_links.xlf:importSelection')) . '">';
69  $markup[] = ' ' . $this->iconFactory->getIcon('actions-document-import-t3d', IconSize::SMALL);
70  $markup[] = ' ' . htmlspecialchars($this->‪getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_browse_links.xlf:importSelection'));
71  $markup[] = ' </button>';
72  $markup[] = ' </div>';
73  $markup[] = ' </div>';
74  $markup[] = ' <div class="col-auto">';
75  $markup[] = ' ' . $this->‪getViewModeButton();
76  $markup[] = ' </div>';
77  $markup[] = '</div>';
78 
79  // Create the filelist
80  $this->filelist->start(
81  $this->selectedFolder,
82  ‪MathUtility::forceIntegerInRange($this->currentPage, 1, 100000),
83  $this->‪getRequest()->getQueryParams()['sort'] ?? '',
84  ($this->‪getRequest()->getQueryParams()['reverse'] ?? '') === '1',
85  Mode::BROWSE
86  );
87  $this->filelist->setResourceDisplayMatcher($this->resourceDisplayMatcher);
88  $this->filelist->setResourceSelectableMatcher($this->resourceSelectableMatcher);
89  $markup[] = $this->filelist->render(null, $this->view);
90 
91  // Build the folder creation form
92  $folderUtilityRenderer = GeneralUtility::makeInstance(FolderUtilityRenderer::class, $this);
93  $markup[] = $folderUtilityRenderer->createFolder($this->‪getRequest(), $this->selectedFolder);
94 
95  $contentHtml = implode('', $markup);
96  }
97 
98  $contentOnly = (bool)($this->‪getRequest()->getQueryParams()['contentOnly'] ?? false);
99  $this->pageRenderer->setTitle($this->‪getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_browse_links.xlf:folderSelector'));
100  $this->view->assign('selectedFolder', $this->selectedFolder);
101  $this->view->assign('content', $contentHtml);
102  $this->view->assign('contentOnly', $contentOnly);
103 
104  $content = $this->view->render('ElementBrowser/Folder');
105  if ($contentOnly) {
106  return $content;
107  }
108  $this->pageRenderer->setBodyContent('<body ' . $this->‪getBodyTagParameters() . '>' . $content);
109  return $this->pageRenderer->render();
110  }
111 }
‪TYPO3\CMS\Filelist\Matcher\ResourceFolderTypeMatcher
Definition: ResourceFolderTypeMatcher.php:27
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\initSelectedFolder
‪initSelectedFolder()
Definition: AbstractResourceBrowser.php:103
‪TYPO3\CMS\Filelist\ElementBrowser
Definition: AbstractResourceBrowser.php:18
‪TYPO3\CMS\Filelist\ElementBrowser\FolderBrowser\render
‪render()
Definition: FolderBrowser.php:55
‪TYPO3\CMS\Filelist\ElementBrowser\FolderBrowser\$identifier
‪string $identifier
Definition: FolderBrowser.php:38
‪TYPO3\CMS\Filelist\Matcher\Matcher
Definition: Matcher.php:24
‪TYPO3\CMS\Filelist\ElementBrowser\FolderBrowser\initVariables
‪initVariables(ServerRequestInterface $request)
Definition: FolderBrowser.php:46
‪TYPO3\CMS\Filelist\ElementBrowser\FolderBrowser
Definition: FolderBrowser.php:36
‪TYPO3\CMS\Backend\ElementBrowser\AbstractElementBrowser\getBodyTagParameters
‪getBodyTagParameters()
Definition: AbstractElementBrowser.php:104
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:38
‪TYPO3\CMS\Backend\ElementBrowser\AbstractElementBrowser\getLanguageService
‪getLanguageService()
Definition: AbstractElementBrowser.php:156
‪TYPO3\CMS\Filelist\Type\Mode
‪Mode
Definition: Mode.php:24
‪TYPO3\CMS\Backend\ElementBrowser\AbstractElementBrowser\getRequest
‪getRequest()
Definition: AbstractElementBrowser.php:151
‪TYPO3\CMS\Filelist\ElementBrowser\FolderBrowser\IDENTIFIER
‪const IDENTIFIER
Definition: FolderBrowser.php:37
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser\getViewModeButton
‪getViewModeButton()
Definition: AbstractResourceBrowser.php:120
‪TYPO3\CMS\Backend\View\FolderUtilityRenderer
Definition: FolderUtilityRenderer.php:36
‪TYPO3\CMS\Filelist\ElementBrowser\FolderBrowser\initialize
‪initialize(ServerRequestInterface $request)
Definition: FolderBrowser.php:40
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:24
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange(mixed $theInt, int $min, int $max=2000000000, int $defaultValue=0)
Definition: MathUtility.php:34
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser
Definition: AbstractResourceBrowser.php:42
‪TYPO3\CMS\Backend\ElementBrowser\AbstractElementBrowser\$request
‪ServerRequestInterface $request
Definition: AbstractElementBrowser.php:65