‪TYPO3CMS  10.4
LiveSearchController.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\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
24 
30 {
37  public function ‪liveSearchAction(ServerRequestInterface $request): ResponseInterface
38  {
39  $queryString = trim($request->getQueryParams()['q']);
40  $liveSearch = GeneralUtility::makeInstance(LiveSearch::class);
41  $queryParser = GeneralUtility::makeInstance(QueryParser::class);
42 
43  $searchResults = [];
44  $liveSearch->setQueryString($queryString);
45  // Jump & edit - find page and retrieve an edit link (this is only for pages
46  if ($queryParser->isValidPageJump($queryString)) {
47  $commandQuery = $queryParser->getCommandForPageJump($queryString);
48  if ($commandQuery) {
49  $queryString = $commandQuery;
50  }
51  }
52  // Search through the database and find records who match to the given search string
53  $resultArray = $liveSearch->find($queryString);
54  foreach ($resultArray as $resultFromTable) {
55  foreach ($resultFromTable as $item) {
56  $searchResults[] = $item;
57  }
58  }
59  return (new ‪JsonResponse())->setPayload($searchResults);
60  }
61 }
‪TYPO3\CMS\Backend\Search\LiveSearch\LiveSearch
Definition: LiveSearch.php:42
‪TYPO3\CMS\Backend\Search\LiveSearch\QueryParser
Definition: QueryParser.php:24
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Controller
Definition: AbstractFormEngineAjaxController.php:18
‪TYPO3\CMS\Backend\Controller\LiveSearchController\liveSearchAction
‪ResponseInterface liveSearchAction(ServerRequestInterface $request)
Definition: LiveSearchController.php:37
‪TYPO3\CMS\Backend\Controller\LiveSearchController
Definition: LiveSearchController.php:30