‪TYPO3CMS  10.4
HelpController.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
33 use TYPO3Fluid\Fluid\View\ViewInterface;
34 
40 {
41  protected const ‪ALLOWED_ACTIONS = ['index', 'all', 'detail'];
42 
46  const ‪FULL = 0;
47 
51  const ‪TOC_ONLY = 1;
52 
56  protected ‪$tableManualRepository;
57 
59  protected ‪$moduleTemplate;
60 
62  protected ‪$view;
63 
67  protected ‪$typo3Information;
68 
75  {
76  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
77  $this->tableManualRepository = GeneralUtility::makeInstance(TableManualRepository::class);
78  $this->typo3Information = ‪$typo3Information;
79  }
80 
87  public function ‪handleRequest(ServerRequestInterface $request): ResponseInterface
88  {
89  $action = $request->getQueryParams()['action'] ?? $request->getParsedBody()['action'] ?? 'index';
90 
91  if ($action === 'detail') {
92  $table = $request->getQueryParams()['table'] ?? $request->getParsedBody()['table'];
93  if (!$table) {
94  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
95  return new ‪RedirectResponse((string)$uriBuilder->buildUriFromRoute('help_cshmanual', [
96  'action' => 'index',
97  ]), 303);
98  }
99  }
100 
101  if (!in_array($action, self::ALLOWED_ACTIONS, true)) {
102  return new HtmlResponse('Action not allowed', 400);
103  }
104 
105  $this->‪initializeView($action);
106 
107  $result = $this->{$action . 'Action'}($request);
108  if ($result instanceof ResponseInterface) {
109  return $result;
110  }
111 
112  $this->‪registerDocheaderButtons($request);
113 
114  $this->moduleTemplate->setContent($this->view->render());
115  return new HtmlResponse($this->moduleTemplate->renderContent());
116  }
117 
121  protected function ‪initializeView(string $templateName)
122  {
123  $this->view = GeneralUtility::makeInstance(StandaloneView::class);
124  $this->view->setTemplate($templateName);
125  $this->view->setTemplateRootPaths(['EXT:backend/Resources/Private/Templates/ContextSensitiveHelp']);
126  $this->view->setPartialRootPaths(['EXT:backend/Resources/Private/Partials']);
127  $this->view->setLayoutRootPaths(['EXT:backend/Resources/Private/Layouts']);
128  $this->view->getRequest()->setControllerExtensionName('Backend');
129  $this->view->assign('copyright', $this->typo3Information->getCopyrightNotice());
130  }
131 
135  public function ‪indexAction()
136  {
137  $this->view->assign('toc', $this->tableManualRepository->getSections(self::TOC_ONLY));
138  }
139 
143  public function ‪allAction()
144  {
145  $this->view->assign('all', $this->tableManualRepository->getSections(self::FULL));
146  }
147 
153  public function ‪detailAction(ServerRequestInterface $request)
154  {
155  $table = $request->getQueryParams()['table'] ?? $request->getParsedBody()['table'];
156  $field = $request->getQueryParams()['field'] ?? $request->getParsedBody()['field'] ?? '*';
157 
158  $mainKey = $table;
159 
160  $this->view->assignMultiple([
161  'table' => $table,
162  'key' => $mainKey,
163  'field' => $field,
164  'manuals' => $field === '*'
165  ? $this->tableManualRepository->getTableManual($mainKey)
166  : [$this->tableManualRepository->getSingleManual($mainKey, $field)],
167  ]);
168  }
169 
175  protected function ‪registerDocheaderButtons(ServerRequestInterface $request)
176  {
177  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
178 
179  if ($this->‪getBackendUser()->mayMakeShortcut()) {
180  $shortcutButton = $buttonBar->makeShortcutButton()
181  ->setModuleName('help_cshmanual')
182  ->setGetVariables(['table', 'field', 'route']);
183  $buttonBar->addButton($shortcutButton);
184  }
185 
186  $action = $request->getQueryParams()['action'] ?? $request->getParsedBody()['action'] ?? 'index';
187  if ($action !== 'index') {
188  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
189  $backButton = $buttonBar->makeLinkButton()
190  ->setTitle($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:back'))
191  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-up', ‪Icon::SIZE_SMALL))
192  ->setHref((string)$uriBuilder->buildUriFromRoute('help_cshmanual'));
193  $buttonBar->addButton($backButton);
194  }
195  }
196 
202  protected function ‪getBackendUser(): BackendUserAuthentication
203  {
204  return ‪$GLOBALS['BE_USER'];
205  }
206 
212  protected function ‪getLanguageService(): LanguageService
213  {
214  return ‪$GLOBALS['LANG'];
215  }
216 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Core\Information\Typo3Information
Definition: Typo3Information.php:26
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Backend\Controller\HelpController
Definition: HelpController.php:40
‪TYPO3\CMS\Backend\Controller\HelpController\indexAction
‪indexAction()
Definition: HelpController.php:131
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:43
‪TYPO3\CMS\Backend\Controller\HelpController\allAction
‪allAction()
Definition: HelpController.php:139
‪TYPO3\CMS\Backend\Controller\HelpController\__construct
‪__construct(Typo3Information $typo3Information)
Definition: HelpController.php:70
‪TYPO3\CMS\Backend\Controller\HelpController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: HelpController.php:57
‪TYPO3\CMS\Backend\Domain\Repository\TableManualRepository
Definition: TableManualRepository.php:30
‪TYPO3\CMS\Backend\Controller\HelpController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: HelpController.php:198
‪TYPO3\CMS\Backend\Controller\HelpController\handleRequest
‪ResponseInterface handleRequest(ServerRequestInterface $request)
Definition: HelpController.php:83
‪TYPO3\CMS\Backend\Controller\HelpController\TOC_ONLY
‪const TOC_ONLY
Definition: HelpController.php:51
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Backend\Controller\HelpController\FULL
‪const FULL
Definition: HelpController.php:46
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Controller\HelpController\initializeView
‪initializeView(string $templateName)
Definition: HelpController.php:117
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:28
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Controller\HelpController\$typo3Information
‪Typo3Information $typo3Information
Definition: HelpController.php:63
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Backend\Controller\HelpController\getLanguageService
‪LanguageService getLanguageService()
Definition: HelpController.php:208
‪TYPO3\CMS\Backend\Controller\HelpController\$tableManualRepository
‪TableManualRepository $tableManualRepository
Definition: HelpController.php:55
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Controller\HelpController\registerDocheaderButtons
‪registerDocheaderButtons(ServerRequestInterface $request)
Definition: HelpController.php:171
‪TYPO3\CMS\Backend\Controller\HelpController\detailAction
‪detailAction(ServerRequestInterface $request)
Definition: HelpController.php:149
‪TYPO3\CMS\Backend\Controller
Definition: AbstractFormEngineAjaxController.php:18
‪TYPO3\CMS\Backend\Controller\HelpController\$view
‪ViewInterface $view
Definition: HelpController.php:59
‪TYPO3\CMS\Backend\Controller\HelpController\ALLOWED_ACTIONS
‪const ALLOWED_ACTIONS
Definition: HelpController.php:41
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26