moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class); $this->tableManualRepository = GeneralUtility::makeInstance(TableManualRepository::class); } /** * Injects the request object for the current request, and renders correct action * * @param ServerRequestInterface $request the current request * @return ResponseInterface the response with the content */ public function handleRequest(ServerRequestInterface $request): ResponseInterface { $action = $request->getQueryParams()['action'] ?? $request->getParsedBody()['action'] ?? 'index'; if ($action === 'detail') { $table = $request->getQueryParams()['table'] ?? $request->getParsedBody()['table']; if (!$table) { $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); return new RedirectResponse((string)$uriBuilder->buildUriFromRoute('help_cshmanual', [ 'action' => 'index', ]), 303); } } if (!in_array($action, self::ALLOWED_ACTIONS, true)) { return new HtmlResponse('Action not allowed', 400); } $this->initializeView($action); $result = call_user_func_array([$this, $action . 'Action'], [$request]); if ($result instanceof ResponseInterface) { return $result; } $this->registerDocheaderButtons($request); $this->moduleTemplate->setContent($this->view->render()); return new HtmlResponse($this->moduleTemplate->renderContent()); } /** * @param string $templateName */ protected function initializeView(string $templateName) { $this->view = GeneralUtility::makeInstance(StandaloneView::class); $this->view->setTemplate($templateName); $this->view->setTemplateRootPaths(['EXT:backend/Resources/Private/Templates/ContextSensitiveHelp']); $this->view->setPartialRootPaths(['EXT:backend/Resources/Private/Partials']); $this->view->setLayoutRootPaths(['EXT:backend/Resources/Private/Layouts']); $this->view->getRequest()->setControllerExtensionName('Backend'); $this->view->assign('copyright', BackendUtility::TYPO3_copyRightNotice()); } /** * Show table of contents */ public function indexAction() { $this->view->assign('toc', $this->tableManualRepository->getSections(self::TOC_ONLY)); } /** * Show the table of contents and all manuals */ public function allAction() { $this->view->assign('all', $this->tableManualRepository->getSections(self::FULL)); } /** * Show a single manual * * @param ServerRequestInterface $request */ public function detailAction(ServerRequestInterface $request) { $table = $request->getQueryParams()['table'] ?? $request->getParsedBody()['table']; $field = $request->getQueryParams()['field'] ?? $request->getParsedBody()['field'] ?? '*'; $mainKey = $table; $this->view->assignMultiple([ 'table' => $table, 'key' => $mainKey, 'field' => $field, 'manuals' => $field === '*' ? $this->tableManualRepository->getTableManual($mainKey) : [$this->tableManualRepository->getSingleManual($mainKey, $field)], ]); } /** * Registers the Icons into the docheader * * @param ServerRequestInterface $request */ protected function registerDocheaderButtons(ServerRequestInterface $request) { $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar(); if ($this->getBackendUser()->mayMakeShortcut()) { $shortcutButton = $buttonBar->makeShortcutButton() ->setModuleName('help_cshmanual') ->setGetVariables(['table', 'field', 'route']); $buttonBar->addButton($shortcutButton); } $action = $request->getQueryParams()['action'] ?? $request->getParsedBody()['action'] ?? 'index'; if ($action !== 'index') { $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); $backButton = $buttonBar->makeLinkButton() ->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:back')) ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-up', Icon::SIZE_SMALL)) ->setHref((string)$uriBuilder->buildUriFromRoute('help_cshmanual')); $buttonBar->addButton($backButton); } } /** * Returns the currently logged in BE user * * @return BackendUserAuthentication */ protected function getBackendUser(): BackendUserAuthentication { return $GLOBALS['BE_USER']; } /** * Returns the LanguageService * * @return LanguageService */ protected function getLanguageService(): LanguageService { return $GLOBALS['LANG']; } }