[TASK] Use BE Routing / PSR-7 instead of BackendUtility::getModuleUrl
[Packages/TYPO3.CMS.git] / typo3 / sysext / documentation / Classes / Controller / HelpController.php
1 <?php
2 namespace TYPO3\CMS\Documentation\Controller;
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\Template\Components\ButtonBar;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3\CMS\Backend\View\BackendTemplateView;
20 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
21 use TYPO3\CMS\Core\Imaging\Icon;
22 use TYPO3\CMS\Core\Localization\LanguageService;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24 use TYPO3\CMS\Documentation\Domain\Repository\TableManualRepository;
25 use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
26 use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
27
28 /**
29 * Main help module controller
30 */
31 class HelpController extends ActionController
32 {
33 /**
34 * Section identifiers
35 */
36 const FULL = 0;
37
38 /**
39 * Show only Table of contents
40 */
41 const TOC_ONLY = 1;
42
43 /**
44 * @var TableManualRepository
45 */
46 protected $tableManualRepository;
47
48 /**
49 * Default View Container
50 *
51 * @var BackendTemplateView
52 */
53 protected $defaultViewObjectName = BackendTemplateView::class;
54
55 /**
56 * Initialize the controller
57 */
58 public function initializeAction()
59 {
60 $this->tableManualRepository = GeneralUtility::makeInstance(TableManualRepository::class);
61 }
62
63 /**
64 * Initialize the view
65 *
66 * @param ViewInterface $view The view
67 */
68 public function initializeView(ViewInterface $view)
69 {
70 /** @var BackendTemplateView $view */
71 parent::initializeView($view);
72 $this->registerDocheaderButtons();
73 $view->assign('copyright', BackendUtility::TYPO3_copyRightNotice());
74 }
75
76 /**
77 * Show table of contents
78 */
79 public function indexAction()
80 {
81 $this->view->assign('toc', $this->tableManualRepository->getSections(self::TOC_ONLY));
82 }
83
84 /**
85 * Show the table of contents and all manuals
86 */
87 public function allAction()
88 {
89 $this->view->assign('all', $this->tableManualRepository->getSections(self::FULL));
90 }
91
92 /**
93 * Show a single manual
94 *
95 * @param string $table
96 * @param string $field
97 */
98 public function detailAction($table = '', $field = '*')
99 {
100 if (empty($table)) {
101 $this->forward('index');
102 }
103
104 $mainKey = $table;
105 $identifierParts = GeneralUtility::trimExplode('.', $field);
106 // The field is the second one
107 if (count($identifierParts) > 1) {
108 array_shift($field);
109 // There's at least one extra part
110 $extraIdentifierInformation = [];
111 $extraIdentifierInformation[] = array_shift($identifierParts);
112 // If the ds_pointerField contains a comma, it means the choice of FlexForm DS
113 // is determined by 2 parameters. In this case we have an extra identifier part
114 if (strpos($GLOBALS['TCA'][$table]['columns'][$field]['config']['ds_pointerField'], ',') !== false) {
115 $extraIdentifierInformation[] = array_shift($identifierParts);
116 }
117 // The remaining parts make up the FlexForm field name itself (reassembled with dots)
118 $flexFormField = implode('.', $identifierParts);
119 // Assemble a different main key and switch field to use FlexForm field name
120 $mainKey .= '.' . $field;
121 foreach ($extraIdentifierInformation as $extraKey) {
122 $mainKey .= '.' . $extraKey;
123 }
124 $field = $flexFormField;
125 }
126
127 $this->view->assignMultiple([
128 'table' => $table,
129 'key' => $mainKey,
130 'field' => $field,
131 'manuals' => $field === '*' ? $this->tableManualRepository->getTableManual($mainKey) : [$this->tableManualRepository->getSingleManual($mainKey, $field)],
132 ]);
133 }
134
135 /**
136 * Registers the Icons into the docheader
137 *
138 * @throws \InvalidArgumentException
139 */
140 protected function registerDocheaderButtons()
141 {
142 /** @var ButtonBar $buttonBar */
143 $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
144 $currentRequest = $this->request;
145 $moduleName = $currentRequest->getPluginName();
146 $getVars = $this->request->getArguments();
147
148 $mayMakeShortcut = $this->getBackendUser()->mayMakeShortcut();
149
150 if ($mayMakeShortcut) {
151 $extensionName = $currentRequest->getControllerExtensionName();
152 if (count($getVars) === 0) {
153 $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
154 $getVars = ['id', 'route', $modulePrefix];
155 }
156 $shortcutButton = $buttonBar->makeShortcutButton()
157 ->setModuleName($moduleName)
158 ->setGetVariables($getVars);
159 $buttonBar->addButton($shortcutButton);
160 }
161
162 if (isset($getVars['action']) && $getVars['action'] !== 'index') {
163 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
164 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
165 $backButton = $buttonBar->makeLinkButton()
166 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:back'))
167 ->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-view-go-up', Icon::SIZE_SMALL))
168 ->setHref((string)$uriBuilder->buildUriFromRoute($moduleName));
169 $buttonBar->addButton($backButton);
170 }
171 }
172
173 /**
174 * Returns the currently logged in BE user
175 *
176 * @return BackendUserAuthentication
177 */
178 protected function getBackendUser()
179 {
180 return $GLOBALS['BE_USER'];
181 }
182
183 /**
184 * Returns the LanguageService
185 *
186 * @return LanguageService
187 */
188 protected function getLanguageService()
189 {
190 return $GLOBALS['LANG'];
191 }
192 }