HelpToolbarItem.php 4.39 KB
Newer Older
Felix Kopp's avatar
Felix Kopp committed
1
2
3
<?php
namespace TYPO3\CMS\Backend\Backend\ToolbarItems;

4
/*
Felix Kopp's avatar
Felix Kopp committed
5
6
7
8
9
10
11
12
13
14
15
16
 * This file is part of the TYPO3 CMS project.
 *
 * 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.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

17
18
use TYPO3\CMS\Backend\Domain\Repository\Module\BackendModuleRepository;
use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
19
20
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
Felix Kopp's avatar
Felix Kopp committed
21
use TYPO3\CMS\Core\Utility\GeneralUtility;
22
use TYPO3\CMS\Fluid\View\StandaloneView;
Felix Kopp's avatar
Felix Kopp committed
23
24

/**
25
 * Help toolbar item
Felix Kopp's avatar
Felix Kopp committed
26
 */
27
28
29
30
31
32
class HelpToolbarItem implements ToolbarItemInterface
{
    /**
     * @var \SplObjectStorage<BackendModule>
     */
    protected $helpModuleMenu = null;
Felix Kopp's avatar
Felix Kopp committed
33

34
35
36
37
38
    /**
     * @var IconFactory
     */
    protected $iconFactory;

39
40
41
42
43
44
45
46
47
48
49
50
    /**
     * Constructor
     */
    public function __construct()
    {
        /** @var BackendModuleRepository $backendModuleRepository */
        $backendModuleRepository = GeneralUtility::makeInstance(BackendModuleRepository::class);
        /** @var \TYPO3\CMS\Backend\Domain\Model\Module\BackendModule $helpModuleMenu */
        $helpModuleMenu = $backendModuleRepository->findByModuleName('help');
        if ($helpModuleMenu && $helpModuleMenu->getChildren()->count() > 0) {
            $this->helpModuleMenu = $helpModuleMenu;
        }
51
        $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
52
    }
53

54
55
56
57
58
59
60
61
62
63
    /**
     * Users see this if a module is available
     *
     * @return bool TRUE
     */
    public function checkAccess()
    {
        $result = (bool)$this->helpModuleMenu;
        return $result;
    }
Felix Kopp's avatar
Felix Kopp committed
64

65
66
67
68
69
70
71
    /**
     * Render help icon
     *
     * @return string Help
     */
    public function getItem()
    {
72
        $icon = $this->iconFactory->getIcon('apps-toolbar-menu-help', Icon::SIZE_SMALL)->render('inline');
73
74
75

        $view = $this->getFluidTemplateObject('HelpToolbarItem.html');
        $view->assignMultiple([
76
                'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:toolbarItems.help',
77
78
79
80
81
                'icon' => $icon
            ]
        );

        return $view->render();
82
    }
Felix Kopp's avatar
Felix Kopp committed
83

84
85
86
87
88
89
90
    /**
     * Render drop down
     *
     * @return string
     */
    public function getDropDown()
    {
91
92
        $view = $this->getFluidTemplateObject('HelpToolbarItemDropDown.html');
        $view->assignMultiple([
93
                'title' =>  'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:rm.clearCache_clearCache',
94
95
96
97
98
                'modules' => $this->helpModuleMenu->getChildren()
            ]
        );

        return $view->render();
99
    }
Felix Kopp's avatar
Felix Kopp committed
100

101
102
103
104
105
106
107
    /**
     * No additional attributes needed.
     *
     * @return array
     */
    public function getAdditionalAttributes()
    {
108
        return [];
109
    }
Felix Kopp's avatar
Felix Kopp committed
110

111
112
113
114
115
116
117
118
119
    /**
     * This item has a drop down
     *
     * @return bool
     */
    public function hasDropDown()
    {
        return true;
    }
Felix Kopp's avatar
Felix Kopp committed
120

121
122
123
124
125
126
127
128
129
    /**
     * Position relative to others
     *
     * @return int
     */
    public function getIndex()
    {
        return 70;
    }
130
131
132
133
134
135
136
137
138
139

    /**
     * Returns LanguageService
     *
     * @return \TYPO3\CMS\Lang\LanguageService
     */
    protected function getLanguageService()
    {
        return $GLOBALS['LANG'];
    }
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160

    /**
     * Returns a new standalone view, shorthand function
     *
     * @param string $filename Which templateFile should be used.
     *
     * @return StandaloneView
     */
    protected function getFluidTemplateObject(string $filename):StandaloneView
    {
        /** @var StandaloneView $view */
        $view = GeneralUtility::makeInstance(StandaloneView::class);
        $view->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Layouts')]);
        $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials/ToolbarItems')]);
        $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/ToolbarItems')]);

        $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/ToolbarItems/' . $filename));

        $view->getRequest()->setControllerExtensionName('Backend');
        return $view;
    }
Felix Kopp's avatar
Felix Kopp committed
161
}