‪TYPO3CMS  ‪main
FolderLinkHandler.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;
29 
34 {
35  protected ‪LinkType ‪$type = LinkType::FOLDER;
36 
37  public function ‪initializeVariables(ServerRequestInterface $request): void
38  {
39  parent::initializeVariables($request);
40  $this->pageRenderer->loadJavaScriptModule('@typo3/filelist/linkbrowser-folder-handler.js');
41 
42  $this->resourceDisplayMatcher = GeneralUtility::makeInstance(Matcher::class);
43  $this->resourceDisplayMatcher->addMatcher(GeneralUtility::makeInstance(ResourceFolderTypeMatcher::class));
44  }
45 
46  public function ‪render(ServerRequestInterface $request): string
47  {
48  $contentHtml = '';
49  if ($this->selectedFolder !== null) {
50  $markup = [];
51 
52  // Create the filelist header bar
53  $markup[] = '<div class="row justify-content-between mb-2">';
54  $markup[] = ' <div class="col-auto"></div>';
55  $markup[] = ' <div class="col-auto">';
56  $markup[] = ' ' . $this->‪getViewModeButton($request);
57  $markup[] = ' </div>';
58  $markup[] = '</div>';
59 
60  // Create the filelist
61  $this->filelist->start(
62  $this->selectedFolder,
63  ‪MathUtility::forceIntegerInRange($this->currentPage, 1, 100000),
64  $request->getQueryParams()['sort'] ?? '',
65  ($request->getQueryParams()['reverse'] ?? '') === '1',
66  Mode::BROWSE
67  );
68  $this->filelist->setResourceDisplayMatcher($this->resourceDisplayMatcher);
69  $this->filelist->setResourceSelectableMatcher($this->resourceSelectableMatcher);
70 
71  $resource = $this->linkParts['url']['folder'] ?? null;
72  if ($resource instanceof ‪ResourceInterface) {
73  $resourceSelectedMatcher = GeneralUtility::makeInstance(Matcher::class);
74  $resourceMatcher = GeneralUtility::makeInstance(ResourceMatcher::class);
75  $resourceMatcher->addResource($resource);
76  $resourceSelectedMatcher->addMatcher($resourceMatcher);
77  $this->filelist->setResourceSelectedMatcher($resourceSelectedMatcher);
78  }
79 
80  $markup[] = $this->filelist->render(null, $this->view);
81 
82  // Build the file upload and folder creation form
83  $folderUtilityRenderer = GeneralUtility::makeInstance(FolderUtilityRenderer::class, $this);
84  $markup[] = $folderUtilityRenderer->createFolder($request, $this->selectedFolder);
85 
86  $contentHtml = implode(PHP_EOL, $markup);
87  }
88 
89  $this->view->assign('selectedFolder', $this->selectedFolder);
90  $this->view->assign('selectedFolderLink', (GeneralUtility::makeInstance(LinkService::class))->asString(['type' => ‪LinkService::TYPE_FOLDER, 'folder' => $this->selectedFolder]));
91  $this->view->assign('content', $contentHtml);
92  $this->view->assign('contentOnly', (bool)($request->getQueryParams()['contentOnly'] ?? false));
93  $this->view->assign('treeActions', ['link']);
94  $this->view->assign('currentIdentifier', !empty($this->linkParts) ? $this->linkParts['url']['folder']->getCombinedIdentifier() : '');
95 
96  return $this->view->render('LinkHandler/Folder');
97  }
98 }
‪TYPO3\CMS\Filelist\Matcher\ResourceMatcher
Definition: ResourceMatcher.php:26
‪TYPO3\CMS\Filelist\Matcher\ResourceFolderTypeMatcher
Definition: ResourceFolderTypeMatcher.php:27
‪TYPO3\CMS\Filelist\Matcher\Matcher
Definition: Matcher.php:24
‪TYPO3\CMS\Filelist\Type\LinkType
‪LinkType
Definition: LinkType.php:28
‪TYPO3\CMS\Filelist\Type\Mode
‪Mode
Definition: Mode.php:24
‪TYPO3\CMS\Backend\View\FolderUtilityRenderer
Definition: FolderUtilityRenderer.php:36
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:24
‪TYPO3\CMS\Core\Resource\ResourceInterface
Definition: ResourceInterface.php:21
‪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