‪TYPO3CMS  9.5
HelpController.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
31 use TYPO3Fluid\Fluid\View\ViewInterface;
32 
38 {
39  protected const ‪ALLOWED_ACTIONS = ['index', 'all', 'detail'];
40 
44  const ‪FULL = 0;
45 
49  const ‪TOC_ONLY = 1;
50 
54  protected ‪$tableManualRepository;
55 
57  protected ‪$moduleTemplate;
58 
60  protected ‪$view;
61 
65  public function ‪__construct()
66  {
67  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
68  $this->tableManualRepository = GeneralUtility::makeInstance(TableManualRepository::class);
69  }
70 
77  public function ‪handleRequest(ServerRequestInterface $request): ResponseInterface
78  {
79  $action = $request->getQueryParams()['action'] ?? $request->getParsedBody()['action'] ?? 'index';
80 
81  if ($action === 'detail') {
82  $table = $request->getQueryParams()['table'] ?? $request->getParsedBody()['table'];
83  if (!$table) {
84  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
85  return new ‪RedirectResponse((string)$uriBuilder->buildUriFromRoute('help_cshmanual', [
86  'action' => 'index',
87  ]), 303);
88  }
89  }
90 
91  if (!in_array($action, self::ALLOWED_ACTIONS, true)) {
92  return new HtmlResponse('Action not allowed', 400);
93  }
94 
95  $this->‪initializeView($action);
96 
97  $result = call_user_func_array([$this, $action . 'Action'], [$request]);
98  if ($result instanceof ResponseInterface) {
99  return $result;
100  }
101 
102  $this->‪registerDocheaderButtons($request);
103 
104  $this->moduleTemplate->setContent($this->view->render());
105  return new HtmlResponse($this->moduleTemplate->renderContent());
106  }
107 
111  protected function ‪initializeView(string $templateName)
112  {
113  $this->view = GeneralUtility::makeInstance(StandaloneView::class);
114  $this->view->setTemplate($templateName);
115  $this->view->setTemplateRootPaths(['EXT:backend/Resources/Private/Templates/ContextSensitiveHelp']);
116  $this->view->setPartialRootPaths(['EXT:backend/Resources/Private/Partials']);
117  $this->view->setLayoutRootPaths(['EXT:backend/Resources/Private/Layouts']);
118  $this->view->getRequest()->setControllerExtensionName('Backend');
119  $this->view->assign('copyright', ‪BackendUtility::TYPO3_copyRightNotice());
120  }
121 
125  public function ‪indexAction()
126  {
127  $this->view->assign('toc', $this->tableManualRepository->getSections(self::TOC_ONLY));
128  }
129 
133  public function ‪allAction()
134  {
135  $this->view->assign('all', $this->tableManualRepository->getSections(self::FULL));
136  }
137 
143  public function ‪detailAction(ServerRequestInterface $request)
144  {
145  $table = $request->getQueryParams()['table'] ?? $request->getParsedBody()['table'];
146  $field = $request->getQueryParams()['field'] ?? $request->getParsedBody()['field'] ?? '*';
147 
148  $mainKey = $table;
149 
150  $this->view->assignMultiple([
151  'table' => $table,
152  'key' => $mainKey,
153  'field' => $field,
154  'manuals' => $field === '*'
155  ? $this->tableManualRepository->getTableManual($mainKey)
156  : [$this->tableManualRepository->getSingleManual($mainKey, $field)],
157  ]);
158  }
159 
165  protected function ‪registerDocheaderButtons(ServerRequestInterface $request)
166  {
167  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
168 
169  if ($this->‪getBackendUser()->mayMakeShortcut()) {
170  $shortcutButton = $buttonBar->makeShortcutButton()
171  ->setModuleName('help_cshmanual')
172  ->setGetVariables(['table', 'field', 'route']);
173  $buttonBar->addButton($shortcutButton);
174  }
175 
176  $action = $request->getQueryParams()['action'] ?? $request->getParsedBody()['action'] ?? 'index';
177  if ($action !== 'index') {
178  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
179  $backButton = $buttonBar->makeLinkButton()
180  ->setTitle($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:back'))
181  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-up', ‪Icon::SIZE_SMALL))
182  ->setHref((string)$uriBuilder->buildUriFromRoute('help_cshmanual'));
183  $buttonBar->addButton($backButton);
184  }
185  }
186 
192  protected function ‪getBackendUser(): BackendUserAuthentication
193  {
194  return ‪$GLOBALS['BE_USER'];
195  }
196 
202  protected function ‪getLanguageService(): LanguageService
203  {
204  return ‪$GLOBALS['LANG'];
205  }
206 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Backend\Controller\HelpController
Definition: HelpController.php:38
‪TYPO3\CMS\Backend\Controller\HelpController\indexAction
‪indexAction()
Definition: HelpController.php:122
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:40
‪TYPO3\CMS\Backend\Controller\HelpController\allAction
‪allAction()
Definition: HelpController.php:130
‪TYPO3\CMS\Backend\Controller\HelpController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: HelpController.php:55
‪TYPO3\CMS\Backend\Domain\Repository\TableManualRepository
Definition: TableManualRepository.php:29
‪TYPO3\CMS\Backend\Controller\HelpController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: HelpController.php:189
‪TYPO3\CMS\Backend\Controller\HelpController\handleRequest
‪ResponseInterface handleRequest(ServerRequestInterface $request)
Definition: HelpController.php:74
‪TYPO3\CMS\Backend\Controller\HelpController\TOC_ONLY
‪const TOC_ONLY
Definition: HelpController.php:49
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:35
‪TYPO3\CMS\Backend\Controller\HelpController\FULL
‪const FULL
Definition: HelpController.php:44
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Backend\Controller\HelpController\initializeView
‪initializeView(string $templateName)
Definition: HelpController.php:108
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:27
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Controller\HelpController\__construct
‪__construct()
Definition: HelpController.php:62
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Backend\Controller\HelpController\getLanguageService
‪LanguageService getLanguageService()
Definition: HelpController.php:199
‪TYPO3\CMS\Backend\Controller\HelpController\$tableManualRepository
‪TableManualRepository $tableManualRepository
Definition: HelpController.php:53
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Controller\HelpController\registerDocheaderButtons
‪registerDocheaderButtons(ServerRequestInterface $request)
Definition: HelpController.php:162
‪TYPO3\CMS\Backend\Controller\HelpController\detailAction
‪detailAction(ServerRequestInterface $request)
Definition: HelpController.php:140
‪TYPO3\CMS\Backend\Controller
Definition: AbstractFormEngineAjaxController.php:3
‪TYPO3\CMS\Backend\Controller\HelpController\$view
‪ViewInterface $view
Definition: HelpController.php:57
‪TYPO3\CMS\Backend\Controller\HelpController\ALLOWED_ACTIONS
‪const ALLOWED_ACTIONS
Definition: HelpController.php:39
‪TYPO3\CMS\Backend\Utility\BackendUtility\TYPO3_copyRightNotice
‪static string TYPO3_copyRightNotice()
Definition: BackendUtility.php:4370
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:25