[BUGFIX] Usage of undefined variables in ShortcutToolbarItem
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Toolbar / LiveSearchToolbarItem.php
1 <?php
2 namespace TYPO3\CMS\Backend\Toolbar;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2013 Michael Klapper <michael.klapper@aoemedia.de>
8 * (c) 2010-2013 Jeff Segars <jeff@webempoweredchurch.org>
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the text file GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * Adds backend live search to the toolbar
32 *
33 * @author Michael Klapper <michael.klapper@aoemedia.de>
34 * @author Jeff Segars <jeff@webempoweredchurch.org>
35 */
36 class LiveSearchToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookInterface {
37
38 /**
39 * Reference back to the backend object
40 *
41 * @var \TYPO3\CMS\Backend\Controller\BackendController
42 */
43 protected $backendReference;
44
45 /**
46 * Constructor
47 *
48 * @param \TYPO3\CMS\Backend\Controller\BackendController $backendReference TYPO3 backend object reference
49 */
50 public function __construct(\TYPO3\CMS\Backend\Controller\BackendController &$backendReference = NULL) {
51 $this->backendReference = $backendReference;
52 }
53
54 /**
55 * Checks whether the user has access to this toolbar item
56 *
57 * @return boolean TRUE if user has access, FALSE if not
58 */
59 public function checkAccess() {
60 $access = FALSE;
61 // Loads the backend modules available for the logged in user.
62 $loadModules = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Module\\ModuleLoader');
63 $loadModules->observeWorkspaces = TRUE;
64 $loadModules->load($GLOBALS['TBE_MODULES']);
65 // Live search is heavily dependent on the list module and only available when that module is.
66 if (is_array($loadModules->modules['web']['sub']['list'])) {
67 $access = TRUE;
68 }
69 return $access;
70 }
71
72 /**
73 * Creates the selector for workspaces
74 *
75 * @return string Workspace selector as HTML select
76 */
77 public function render() {
78 $this->addJavascriptToBackend();
79 return '<div class="live-search-wrapper">
80 <span title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:search') . '" class="t3-icon t3-icon-apps t3-icon-apps-toolbar t3-icon-toolbar-menu-search">&nbsp;</span>
81 <input id="live-search-box" />
82 </div>';
83 }
84
85 /**
86 * Adds the necessary JavaScript to the backend
87 *
88 * @return void
89 */
90 protected function addJavascriptToBackend() {
91 $pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
92 $this->backendReference->addJavascriptFile('sysext/backend/Resources/Public/JavaScript/livesearch.js');
93 }
94
95 /**
96 * returns additional attributes for the list item in the toolbar
97 *
98 * @return string List item HTML attributes
99 */
100 public function getAdditionalAttributes() {
101 return ' id="live-search-menu"';
102 }
103
104 }