Skip to content

Commit

Permalink
[BUGFIX] Add missing file search to file link handler
Browse files Browse the repository at this point in the history
The FileLinkHandler, used to select a file
in the link wizard does now also allow to
search for files, like it's also possible
in the FileBrowser already.

Resolves: #103241
Releases: main, 12.4
Change-Id: Icf3ded3d317e5fbdbd4bc17db0e5969f7b2a055f
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83111
Tested-by: core-ci <typo3@b13.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
  • Loading branch information
o-ba committed Mar 4, 2024
1 parent bfd7cf9 commit d5d7ee3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
37 changes: 25 additions & 12 deletions typo3/sysext/filelist/Classes/LinkHandler/FileLinkHandler.php
Expand Up @@ -17,7 +17,9 @@

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\View\FolderUtilityRenderer;
use TYPO3\CMS\Backend\View\RecordSearchBoxComponent;
use TYPO3\CMS\Core\Resource\ResourceInterface;
use TYPO3\CMS\Core\Resource\Search\FileSearchDemand;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Filelist\Matcher\Matcher;
Expand Down Expand Up @@ -60,16 +62,6 @@ public function render(ServerRequestInterface $request): string
{
$contentHtml = '';
if ($this->selectedFolder !== null) {
$markup = [];

// Create the filelist header bar
$markup[] = '<div class="row justify-content-between mb-2">';
$markup[] = ' <div class="col-auto"></div>';
$markup[] = ' <div class="col-auto">';
$markup[] = ' ' . $this->getViewModeButton($request);
$markup[] = ' </div>';
$markup[] = '</div>';

// Create the filelist
$this->filelist->start(
$this->selectedFolder,
Expand All @@ -81,6 +73,9 @@ public function render(ServerRequestInterface $request): string
$this->filelist->setResourceDisplayMatcher($this->resourceDisplayMatcher);
$this->filelist->setResourceSelectableMatcher($this->resourceSelectableMatcher);

$searchWord = trim((string)($request->getParsedBody()['searchTerm'] ?? $request->getQueryParams()['searchTerm'] ?? ''));
$searchDemand = $searchWord !== '' ? FileSearchDemand::createForSearchTerm($searchWord)->withFolder($this->selectedFolder)->withRecursive() : null;

$resource = $this->linkParts['url']['file'] ?? null;
if ($resource instanceof ResourceInterface) {
$resourceSelectedMatcher = GeneralUtility::makeInstance(Matcher::class);
Expand All @@ -90,9 +85,27 @@ public function render(ServerRequestInterface $request): string
$this->filelist->setResourceSelectedMatcher($resourceSelectedMatcher);
}

$markup[] = $this->filelist->render(null, $this->view);
$markup = [];

// Render the filelist search box
$markup[] = '<div class="mb-4">';
$markup[] = GeneralUtility::makeInstance(RecordSearchBoxComponent::class)
->setSearchWord($searchWord)
->render($request, $this->filelist->createModuleUri($this->getUrlParameters([])));
$markup[] = '</div>';

// Render the filelist header bar
$markup[] = '<div class="row justify-content-between mb-2">';
$markup[] = ' <div class="col-auto"></div>';
$markup[] = ' <div class="col-auto">';
$markup[] = ' ' . $this->getViewModeButton($request);
$markup[] = ' </div>';
$markup[] = '</div>';

// Render the filelist
$markup[] = $this->filelist->render($searchDemand, $this->view);

// Build the file upload and folder creation form
// Render the file upload and folder creation form
$folderUtilityRenderer = GeneralUtility::makeInstance(FolderUtilityRenderer::class, $this);
$markup[] = $folderUtilityRenderer->uploadForm($this->selectedFolder);
$markup[] = $folderUtilityRenderer->createFolder($this->selectedFolder);
Expand Down
Expand Up @@ -15,7 +15,7 @@

<f:section name="Content">
<f:if condition="{selectedFolder}">
<h4 class="text-truncate">
<h4 class="text-truncate mb-4">
<core:iconForResource resource="{selectedFolder}" />
{selectedFolder.storage.name}: {selectedFolder.identifier}
</h4>
Expand Down
Expand Up @@ -16,7 +16,7 @@

<f:section name="Content">
<f:if condition="{selectedFolder}">
<h4 class="text-truncate">
<h4 class="text-truncate mb-4">
<core:iconForResource resource="{selectedFolder}" />
<f:render section="LinkWrap" contentAs="linkText" arguments="{_all}">
{selectedFolder.storage.name}: {selectedFolder.identifier}
Expand Down

0 comments on commit d5d7ee3

Please sign in to comment.