[TASK] Move texts from code to language file
[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 ';
64 }
65
66 /**
67 * This item needs to additional attributes
68 *
69 * @return array
70 */
71 public function getAdditionalAttributes() {
72 return array();
73 }
74
75 /**
76 * This item has no drop down
77 *
78 * @return bool
79 */
80 public function hasDropDown() {
81 return FALSE;
82 }
83
84 /**
85 * No drop down here
86 *
87 * @return string
88 */
89 public function getDropDown() {
90 return '';
91 }
92
93 /**
94 * Position relative to others, live search should be very right
95 *
96 * @return int
97 */
98 public function getIndex() {
99 return 90;
100 }
101
102 /**
103 * Returns current PageRenderer
104 *
105 * @return PageRenderer
106 */
107 protected function getPageRenderer() {
108 return GeneralUtility::makeInstance(PageRenderer::class);
109 }
110
111 }