LiveSearchToolbarItem.php 4.01 KB
Newer Older
1
<?php
2
namespace TYPO3\CMS\Backend\Backend\ToolbarItems;
3

4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
8
9
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
10
 *
11
12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
15
 * The TYPO3 project - inspiring people to share!
 */
16

17
use TYPO3\CMS\Backend\Domain\Repository\Module\BackendModuleRepository;
18
use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
19
20
use TYPO3\CMS\Core\Imaging\Icon;
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
27
/**
 * Adds backend live search to the toolbar
 */
28
29
class LiveSearchToolbarItem implements ToolbarItemInterface
{
30
31
32
33
34
    /**
     * @var IconFactory
     */
    protected $iconFactory;

35
36
37
38
39
40
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/LiveSearch');
41
        $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
42
    }
43

44
45
46
47
48
49
50
51
52
53
54
    /**
     * Checks whether the user has access to this toolbar item,
     * only allowed when the list module is available
     *
     * @return bool TRUE if user has access, FALSE if not
     */
    public function checkAccess()
    {
        /** @var BackendModuleRepository $backendModuleRepository */
        $backendModuleRepository = GeneralUtility::makeInstance(BackendModuleRepository::class);
        /** @var \TYPO3\CMS\Backend\Domain\Model\Module\BackendModule $listModule */
55

56
57
58
59
        // Live search is heavily dependent on the list module and only available when that module is.
        $listModule = $backendModuleRepository->findByModuleName('web_list');
        return $listModule !== null;
    }
60

61
62
63
64
65
66
67
68
    /**
     * Render search field
     *
     * @return string Live search form HTML
     */
    public function getItem()
    {
        return '
69
			<form class="t3js-topbar-navigation-search toolbar-item-search-form live-search-wrapper" role="search">
Benjamin Kott's avatar
Benjamin Kott committed
70
				<div class="form-group">
71
72
73
74
                    <div class="form-control-holder">
                        <div class="form-control-icon">
                            ' . $this->iconFactory->getIcon('apps-toolbar-menu-search', Icon::SIZE_SMALL)->render('inline') . '
                        </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
78
				</div>
			</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
86
87
88
89
90
    /**
     * This item needs to additional attributes
     *
     * @return array
     */
    public function getAdditionalAttributes()
    {
91
        return ['class' => 'toolbar-item-search t3js-toolbar-item-search'];
92
    }
93

94
95
96
97
98
99
100
101
102
    /**
     * This item has no drop down
     *
     * @return bool
     */
    public function hasDropDown()
    {
        return false;
    }
103

104
105
106
107
108
109
110
111
112
    /**
     * No drop down here
     *
     * @return string
     */
    public function getDropDown()
    {
        return '';
    }
113

114
115
116
117
118
119
120
121
122
    /**
     * Position relative to others, live search should be very right
     *
     * @return int
     */
    public function getIndex()
    {
        return 90;
    }
123

124
125
126
127
128
129
130
131
132
    /**
     * Returns current PageRenderer
     *
     * @return PageRenderer
     */
    protected function getPageRenderer()
    {
        return GeneralUtility::makeInstance(PageRenderer::class);
    }
133
134
135
136
137
138
139
140
141
142

    /**
     * Returns LanguageService
     *
     * @return LanguageService
     */
    protected function getLanguageService()
    {
        return $GLOBALS['LANG'];
    }
143
}