[CLEANUP] Streamline backend toolbar items
[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\Utility\GeneralUtility;
20 use TYPO3\CMS\Fluid\View\StandaloneView;
21
22 /**
23 * Help toolbar item
24 */
25 class HelpToolbarItem implements ToolbarItemInterface
26 {
27 /**
28 * @var \SplObjectStorage<BackendModule>
29 */
30 protected $helpModuleMenu = null;
31
32 /**
33 * Constructor
34 */
35 public function __construct()
36 {
37 $backendModuleRepository = GeneralUtility::makeInstance(BackendModuleRepository::class);
38 $helpModuleMenu = $backendModuleRepository->findByModuleName('help');
39 if ($helpModuleMenu && $helpModuleMenu->getChildren()->count() > 0) {
40 $this->helpModuleMenu = $helpModuleMenu;
41 }
42 }
43
44 /**
45 * Users see this if a module is available
46 *
47 * @return bool TRUE
48 */
49 public function checkAccess()
50 {
51 return (bool)$this->helpModuleMenu;
52 }
53
54 /**
55 * Render help icon
56 *
57 * @return string toolbar item for the help icon
58 */
59 public function getItem()
60 {
61 return $this->getFluidTemplateObject('HelpToolbarItem.html')->render();
62 }
63
64 /**
65 * Render drop down
66 *
67 * @return string
68 */
69 public function getDropDown()
70 {
71 $view = $this->getFluidTemplateObject('HelpToolbarItemDropDown.html');
72 $view->assign('modules', $this->helpModuleMenu->getChildren());
73 return $view->render();
74 }
75
76 /**
77 * No additional attributes needed.
78 *
79 * @return array
80 */
81 public function getAdditionalAttributes()
82 {
83 return [];
84 }
85
86 /**
87 * This item has a drop down
88 *
89 * @return bool
90 */
91 public function hasDropDown()
92 {
93 return true;
94 }
95
96 /**
97 * Position relative to others
98 *
99 * @return int
100 */
101 public function getIndex()
102 {
103 return 70;
104 }
105
106 /**
107 * Returns a new standalone view, shorthand function
108 *
109 * @param string $filename Which templateFile should be used.
110 * @return StandaloneView
111 */
112 protected function getFluidTemplateObject(string $filename): StandaloneView
113 {
114 $view = GeneralUtility::makeInstance(StandaloneView::class);
115 $view->setLayoutRootPaths(['EXT:backend/Resources/Private/Layouts']);
116 $view->setPartialRootPaths(['EXT:backend/Resources/Private/Partials/ToolbarItems']);
117 $view->setTemplateRootPaths(['EXT:backend/Resources/Private/Templates/ToolbarItems']);
118 $view->setTemplate($filename);
119
120 $view->getRequest()->setControllerExtensionName('Backend');
121 return $view;
122 }
123 }