From 7cdd863a864d0428813eba8824037fc483a7d542 Mon Sep 17 00:00:00 2001 From: Alexander Schnitzler <typo3@alexanderschnitzler.de> Date: Wed, 23 Sep 2015 15:17:10 +0200 Subject: [PATCH] [FEATURE] Add basic file search in element browser Releases: master Resolves: #69120 Change-Id: I500f4979edebff52a002518189c69acc222e6e65 Reviewed-on: http://review.typo3.org/43503 Reviewed-by: Daniel Goerz <ervaude@gmail.com> Tested-by: Daniel Goerz <ervaude@gmail.com> Tested-by: Daniel Maier <dani-maier@gmx.de> Reviewed-by: Daniel Maier <dani-maier@gmx.de> Reviewed-by: Frans Saris <franssaris@gmail.com> Tested-by: Frans Saris <franssaris@gmail.com> --- ...120-AddBasicFileSearchInElementBrowser.rst | 12 +++++ .../Classes/Browser/ElementBrowser.php | 45 ++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Feature-69120-AddBasicFileSearchInElementBrowser.rst diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-69120-AddBasicFileSearchInElementBrowser.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-69120-AddBasicFileSearchInElementBrowser.rst new file mode 100644 index 000000000000..3ba8322f03d8 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Feature-69120-AddBasicFileSearchInElementBrowser.rst @@ -0,0 +1,12 @@ +========================================================== +Feature: #69120 - Add basic file search in element browser +========================================================== + +Description +=========== + +A file search has been added to the TYPO3 Element Browser. + +The search happens recursively from the currently selected folder in the folder tree. This way it is possible +to search whole mount points or just single folders with a lot of files. + diff --git a/typo3/sysext/recordlist/Classes/Browser/ElementBrowser.php b/typo3/sysext/recordlist/Classes/Browser/ElementBrowser.php index a7f6538970ec..3160e498ffe4 100755 --- a/typo3/sysext/recordlist/Classes/Browser/ElementBrowser.php +++ b/typo3/sysext/recordlist/Classes/Browser/ElementBrowser.php @@ -28,6 +28,7 @@ use TYPO3\CMS\Core\ElementBrowser\ElementBrowserHookInterface; use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Imaging\IconFactory; use TYPO3\CMS\Core\Messaging\FlashMessage; +use TYPO3\CMS\Core\Resource\FileRepository; use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry; use TYPO3\CMS\Core\Page\PageRenderer; use TYPO3\CMS\Core\Resource\Exception; @@ -268,11 +269,22 @@ class ElementBrowser { */ protected $hookName = 'typo3/class.browse_links.php'; + /** + * @var string + */ + protected $searchWord; + + /** + * @var FileRepository + */ + protected $fileRepository; + /** * Construct */ public function __construct() { $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class); + $this->fileRepository = GeneralUtility::makeInstance(FileRepository::class); $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); $this->pageRenderer->loadJquery(); $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Recordlist/FieldSelectBox'); @@ -348,6 +360,7 @@ class ElementBrowser { $this->expandFolder = GeneralUtility::_GP('expandFolder'); $this->PM = GeneralUtility::_GP('PM'); $this->RTEtsConfigParams = GeneralUtility::_GP('RTEtsConfigParams'); + $this->searchWord = (string)GeneralUtility::_GP('searchWord'); // Site URL // Current site url @@ -1500,6 +1513,8 @@ class ElementBrowser { </tr> </table> '; + + // Adding create folder + upload forms if applicable: if (!$backendUser->getTSConfigVal('options.uploadFieldsInTopOfEB')) { $content .= $uploadForm; @@ -1876,7 +1891,12 @@ class ElementBrowser { return ''; } $extensionList = $extensionList == '*' ? '' : $extensionList; - $files = $this->getFilesInFolder($folder, $extensionList); + if ($this->searchWord !== '') { + $files = $this->fileRepository->searchByName($folder, $this->searchWord); + } else { + $files = $this->getFilesInFolder($folder, $extensionList); + } + return $this->fileList($files, $folder, $noThumbs); } @@ -1896,6 +1916,7 @@ class ElementBrowser { // Create headline (showing number of files): $filesCount = count($files); $out .= $this->barheader(sprintf($lang->getLL('files') . ' (%s):', $filesCount)); + $out .= $this->getFileSearchField(); $out .= '<div id="filelist">'; $out .= $this->getBulkSelector($filesCount); $titleLen = (int)$this->getBackendUser()->uc['titleLen']; @@ -2621,6 +2642,28 @@ class ElementBrowser { return $out; } + /** + * Get the HTML data required for the file search field of the TYPO3 Element Browser. + * + * @return string HTML data required for the search field in the file list of the Element Browser + */ + protected function getFileSearchField() { + $action = $this->getThisScript() . 'act=' . $this->act . '&mode=' . $this->mode + . '&bparams=' . rawurlencode($this->bparams) + . (is_array($this->P) ? GeneralUtility::implodeArrayForUrl('P', $this->P) : ''); + $out = ' + <form method="post" action="' . htmlspecialchars($action) . '"> + <div class="input-group"> + <input class="form-control" type="text" name="searchWord" value="' . htmlspecialchars($this->searchWord) . '"> + <span class="input-group-btn"> + <button class="btn btn-default" type="submit">' . $this->getLanguageService()->sL('LLL:EXT:filelist/Resources/Private/Language/locallang.xlf:search', TRUE) .'</button> + </span> + </div> + </form>'; + $out .= $this->doc->spacer(15); + return $out; + } + /** * Determines whether submitted field change functions are valid * and are coming from the system and not from an external abuse. -- GitLab