-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathDocModuleController.php
More file actions
70 lines (57 loc) · 2.4 KB
/
Copy pathDocModuleController.php
File metadata and controls
70 lines (57 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
declare(strict_types=1);
namespace GeorgRinger\Doc\Controller;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ControllerInterface;
use TYPO3\CMS\Extbase\Mvc\RequestInterface;
use TYPO3\CMS\Fluid\View\StandaloneView;
class DocModuleController implements ControllerInterface
{
/**
* @param ServerRequestInterface $request the current request
* @return ResponseInterface the response with the content
*/
public function __invoke(ServerRequestInterface $request): ResponseInterface
{
$this->mainAction($request);
}
/**
* @param ServerRequestInterface $request the current request
* @return ResponseInterface the response with the content
*/
public function mainAction(ServerRequestInterface $request): ResponseInterface
{
$view = $this->getStandaloneView();
return new HtmlResponse($view->render());
}
private function getStandaloneView(): StandaloneView
{
$settings = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('doc');
$docRootPath = $settings['documentationRootPath'] ?? '';
if (!$docRootPath) {
throw new \UnexpectedValueException('Documentation root path not set', 1609235458);
}
$documentationName = $settings['documentationName'] ?? 'Documentation';
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$uri = $uriBuilder->buildUriFromRoute('ajax_doc_serve', ['path' => $docRootPath]);
$templatePathAndFilename = GeneralUtility::getFileAbsFileName('EXT:doc/Resources/Private/Templates/Module.html');
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplatePathAndFilename($templatePathAndFilename);
$view->assignMultiple([
'docRootPath' => $uri->__toString(),
'documentationName' => $documentationName,
'darkMode' => $settings['darkMode'] ?? false
]);
return $view;
}
public function processRequest(RequestInterface $request): ResponseInterface
{
$view = $this->getStandaloneView();
return new HtmlResponse($view->render());
}
}