[TASK] Replace Typeahead with jquery autocomplete plugin
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Backend / ToolbarItems / LiveSearchToolbarItem.php
1 <?php
2 namespace TYPO3\CMS\Backend\Backend\ToolbarItems;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Domain\Repository\Module\BackendModuleRepository;
18 use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
19 use TYPO3\CMS\Backend\Module\ModuleLoader;
20 use TYPO3\CMS\Core\Page\PageRenderer;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22
23 /**
24 * Adds backend live search to the toolbar
25 */
26 class LiveSearchToolbarItem implements ToolbarItemInterface {
27
28 /**
29 * Constructor
30 */
31 public function __construct() {
32 $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/LiveSearch');
33 }
34
35 /**
36 * Checks whether the user has access to this toolbar item,
37 * only allowed when the list module is available
38 *
39 * @return bool TRUE if user has access, FALSE if not
40 */
41 public function checkAccess() {
42 /** @var BackendModuleRepository $backendModuleRepository */
43 $backendModuleRepository = GeneralUtility::makeInstance(BackendModuleRepository::class);
44 /** @var \TYPO3\CMS\Backend\Domain\Model\Module\BackendModule $listModule */
45
46 // Live search is heavily dependent on the list module and only available when that module is.
47 $listModule = $backendModuleRepository->findByModuleName('web_list');
48 return $listModule !== NULL;
49 }
50
51 /**
52 * Render search field
53 *
54 * @return string Live search form HTML
55 */
56 public function getItem() {
57 return '
58 <form class="typo3-topbar-navigation-search t3js-topbar-navigation-search live-search-wrapper" role="search">
59 <div class="form-group">
60 <input type="text" class="form-control t3js-topbar-navigation-search-field" placeholder="Search" id="live-search-box" autocomplete="off">
61 </div>
62 </form>
63 <div class="dropdown-menu" role="menu"></div>
64 ';
65 }
66
67 /**
68 * This item needs to additional attributes
69 *
70 * @return array
71 */
72 public function getAdditionalAttributes() {
73 return array('class' => 'dropdown');
74 }
75
76 /**
77 * This item has no drop down
78 *
79 * @return bool
80 */
81 public function hasDropDown() {
82 return FALSE;
83 }
84
85 /**
86 * No drop down here
87 *
88 * @return string
89 */
90 public function getDropDown() {
91 return '';
92 }
93
94 /**
95 * Position relative to others, live search should be very right
96 *
97 * @return int
98 */
99 public function getIndex() {
100 return 90;
101 }
102
103 /**
104 * Returns current PageRenderer
105 *
106 * @return PageRenderer
107 */
108 protected function getPageRenderer() {
109 return GeneralUtility::makeInstance(PageRenderer::class);
110 }
111
112 }