[BUGFIX] Use correct check in search if list module is available
[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\Imaging\Icon;
20 use TYPO3\CMS\Core\Imaging\IconFactory;
21 use TYPO3\CMS\Core\Page\PageRenderer;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23 use TYPO3\CMS\Lang\LanguageService;
24
25 /**
26 * Adds backend live search to the toolbar
27 */
28 class LiveSearchToolbarItem implements ToolbarItemInterface
29 {
30 /**
31 * @var IconFactory
32 */
33 protected $iconFactory;
34
35 /**
36 * Constructor
37 */
38 public function __construct()
39 {
40 $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/LiveSearch');
41 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
42 }
43
44 /**
45 * Checks whether the user has access to this toolbar item,
46 * only allowed when the list module is available
47 *
48 * @return bool TRUE if user has access, FALSE if not
49 */
50 public function checkAccess()
51 {
52 /** @var BackendModuleRepository $backendModuleRepository */
53 $backendModuleRepository = GeneralUtility::makeInstance(BackendModuleRepository::class);
54 /** @var \TYPO3\CMS\Backend\Domain\Model\Module\BackendModule $listModule */
55
56 // Live search is heavily dependent on the list module and only available when that module is.
57 $listModule = $backendModuleRepository->findByModuleName('web_list');
58 return $listModule !== null && $listModule !== false;
59 }
60
61 /**
62 * Render search field
63 *
64 * @return string Live search form HTML
65 */
66 public function getItem()
67 {
68 return '
69 <form class="t3js-topbar-navigation-search toolbar-item-search-form live-search-wrapper" role="search">
70 <div class="form-group">
71 <div class="form-control-holder">
72 <div class="form-control-icon">
73 ' . $this->iconFactory->getIcon('apps-toolbar-menu-search', Icon::SIZE_SMALL)->render('inline') . '
74 </div>
75 <input type="text" class="form-control toolbar-item-search-field t3js-topbar-navigation-search-field" placeholder="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:toolbarItems.search')) . '" id="live-search-box" autocomplete="off">
76 </div>
77 </div>
78 </form>
79 <a href="#" class="dropdown-toggle t3js-toolbar-search-dropdowntoggle" data-toggle="dropdown" aria-expanded="false"></a>
80 <div class="dropdown-menu" role="menu"></div>
81 ';
82 }
83
84 /**
85 * This item needs to additional attributes
86 *
87 * @return array
88 */
89 public function getAdditionalAttributes()
90 {
91 return ['class' => 'toolbar-item-search t3js-toolbar-item-search'];
92 }
93
94 /**
95 * This item has no drop down
96 *
97 * @return bool
98 */
99 public function hasDropDown()
100 {
101 return false;
102 }
103
104 /**
105 * No drop down here
106 *
107 * @return string
108 */
109 public function getDropDown()
110 {
111 return '';
112 }
113
114 /**
115 * Position relative to others, live search should be very right
116 *
117 * @return int
118 */
119 public function getIndex()
120 {
121 return 90;
122 }
123
124 /**
125 * Returns current PageRenderer
126 *
127 * @return PageRenderer
128 */
129 protected function getPageRenderer()
130 {
131 return GeneralUtility::makeInstance(PageRenderer::class);
132 }
133
134 /**
135 * Returns LanguageService
136 *
137 * @return LanguageService
138 */
139 protected function getLanguageService()
140 {
141 return $GLOBALS['LANG'];
142 }
143 }