[TASK] Live search placholder is hard-coded
[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\Core\Page\PageRenderer;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Lang\LanguageService;
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 {
33 $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/LiveSearch');
34 }
35
36 /**
37 * Checks whether the user has access to this toolbar item,
38 * only allowed when the list module is available
39 *
40 * @return bool TRUE if user has access, FALSE if not
41 */
42 public function checkAccess()
43 {
44 /** @var BackendModuleRepository $backendModuleRepository */
45 $backendModuleRepository = GeneralUtility::makeInstance(BackendModuleRepository::class);
46 /** @var \TYPO3\CMS\Backend\Domain\Model\Module\BackendModule $listModule */
47
48 // Live search is heavily dependent on the list module and only available when that module is.
49 $listModule = $backendModuleRepository->findByModuleName('web_list');
50 return $listModule !== null;
51 }
52
53 /**
54 * Render search field
55 *
56 * @return string Live search form HTML
57 */
58 public function getItem()
59 {
60 return '
61 <form class="typo3-topbar-navigation-search t3js-topbar-navigation-search live-search-wrapper" role="search">
62 <div class="form-group">
63 <input type="text" class="form-control t3js-topbar-navigation-search-field" placeholder="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.search', true) . '" id="live-search-box" autocomplete="off">
64 </div>
65 </form>
66 <div class="dropdown-menu" role="menu"></div>
67 ';
68 }
69
70 /**
71 * This item needs to additional attributes
72 *
73 * @return array
74 */
75 public function getAdditionalAttributes()
76 {
77 return array('class' => 'dropdown');
78 }
79
80 /**
81 * This item has no drop down
82 *
83 * @return bool
84 */
85 public function hasDropDown()
86 {
87 return false;
88 }
89
90 /**
91 * No drop down here
92 *
93 * @return string
94 */
95 public function getDropDown()
96 {
97 return '';
98 }
99
100 /**
101 * Position relative to others, live search should be very right
102 *
103 * @return int
104 */
105 public function getIndex()
106 {
107 return 90;
108 }
109
110 /**
111 * Returns current PageRenderer
112 *
113 * @return PageRenderer
114 */
115 protected function getPageRenderer()
116 {
117 return GeneralUtility::makeInstance(PageRenderer::class);
118 }
119
120 /**
121 * Returns LanguageService
122 *
123 * @return LanguageService
124 */
125 protected function getLanguageService()
126 {
127 return $GLOBALS['LANG'];
128 }
129 }