3b55abf9c4e7227e29cd9965dcb2a89f4b107937
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Backend / ToolbarItems / HelpToolbarItem.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\Utility\GeneralUtility;
22 use TYPO3\CMS\Fluid\View\StandaloneView;
23
24 /**
25 * Help toolbar item
26 */
27 class HelpToolbarItem implements ToolbarItemInterface
28 {
29 /**
30 * @var \SplObjectStorage<BackendModule>
31 */
32 protected $helpModuleMenu = null;
33
34 /**
35 * @var IconFactory
36 */
37 protected $iconFactory;
38
39 /**
40 * Constructor
41 */
42 public function __construct()
43 {
44 /** @var BackendModuleRepository $backendModuleRepository */
45 $backendModuleRepository = GeneralUtility::makeInstance(BackendModuleRepository::class);
46 /** @var \TYPO3\CMS\Backend\Domain\Model\Module\BackendModule $helpModuleMenu */
47 $helpModuleMenu = $backendModuleRepository->findByModuleName('help');
48 if ($helpModuleMenu && $helpModuleMenu->getChildren()->count() > 0) {
49 $this->helpModuleMenu = $helpModuleMenu;
50 }
51 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
52 }
53
54 /**
55 * Users see this if a module is available
56 *
57 * @return bool TRUE
58 */
59 public function checkAccess()
60 {
61 $result = (bool)$this->helpModuleMenu;
62 return $result;
63 }
64
65 /**
66 * Render help icon
67 *
68 * @return string Help
69 */
70 public function getItem()
71 {
72 $icon = $this->iconFactory->getIcon('apps-toolbar-menu-help', Icon::SIZE_SMALL)->render('inline');
73
74 $view = $this->getFluidTemplateObject('HelpToolbarItem.html');
75 $view->assignMultiple([
76 'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:toolbarItems.help',
77 'icon' => $icon
78 ]
79 );
80
81 return $view->render();
82 }
83
84 /**
85 * Render drop down
86 *
87 * @return string
88 */
89 public function getDropDown()
90 {
91 $view = $this->getFluidTemplateObject('HelpToolbarItemDropDown.html');
92 $view->assignMultiple([
93 'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:rm.clearCache_clearCache',
94 'modules' => $this->helpModuleMenu->getChildren()
95 ]
96 );
97
98 return $view->render();
99 }
100
101 /**
102 * No additional attributes needed.
103 *
104 * @return array
105 */
106 public function getAdditionalAttributes()
107 {
108 return [];
109 }
110
111 /**
112 * This item has a drop down
113 *
114 * @return bool
115 */
116 public function hasDropDown()
117 {
118 return true;
119 }
120
121 /**
122 * Position relative to others
123 *
124 * @return int
125 */
126 public function getIndex()
127 {
128 return 70;
129 }
130
131 /**
132 * Returns LanguageService
133 *
134 * @return \TYPO3\CMS\Lang\LanguageService
135 */
136 protected function getLanguageService()
137 {
138 return $GLOBALS['LANG'];
139 }
140
141 /**
142 * Returns a new standalone view, shorthand function
143 *
144 * @param string $filename Which templateFile should be used.
145 *
146 * @return StandaloneView
147 */
148 protected function getFluidTemplateObject(string $filename):StandaloneView
149 {
150 /** @var StandaloneView $view */
151 $view = GeneralUtility::makeInstance(StandaloneView::class);
152 $view->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Layouts')]);
153 $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials/ToolbarItems')]);
154 $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/ToolbarItems')]);
155
156 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/ToolbarItems/' . $filename));
157
158 $view->getRequest()->setControllerExtensionName('Backend');
159 return $view;
160 }
161 }