|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +namespace GeorgRinger\Doc\Controller; |
| 5 | + |
| 6 | +use Psr\Http\Message\ResponseInterface; |
| 7 | +use Psr\Http\Message\ServerRequestInterface; |
| 8 | +use TYPO3\CMS\Core\Http\HtmlResponse; |
| 9 | +use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; |
| 10 | +use TYPO3\CMS\Core\Utility\GeneralUtility; |
| 11 | +use TYPO3\CMS\Core\Utility\PathUtility; |
| 12 | +use TYPO3\CMS\Fluid\View\StandaloneView; |
| 13 | + |
| 14 | + |
| 15 | +class DocModuleController |
| 16 | +{ |
| 17 | + |
| 18 | + |
| 19 | + /** |
| 20 | + * @param ServerRequestInterface $request the current request |
| 21 | + * @return ResponseInterface the response with the content |
| 22 | + */ |
| 23 | + public function mainAction(ServerRequestInterface $request): ResponseInterface |
| 24 | + { |
| 25 | + $view = $this->getStandaloneView(); |
| 26 | + return new HtmlResponse($view->render()); |
| 27 | + } |
| 28 | + |
| 29 | + private function getStandaloneView(): StandaloneView |
| 30 | + { |
| 31 | + $settings = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class)->get('doc'); |
| 32 | + $docRootPath = $settings['documentationRootPath'] ?? ''; |
| 33 | + if (!$docRootPath) { |
| 34 | + throw new \UnexpectedValueException('Documentation root path not set', 1609235458); |
| 35 | + } |
| 36 | + |
| 37 | + $publicResourcesPath = '../../' . PathUtility::getRelativePathTo(ExtensionManagementUtility::extPath('doc')) . 'Resources/Public/docsify/'; |
| 38 | + |
| 39 | + |
| 40 | + $templatePathAndFilename = GeneralUtility::getFileAbsFileName('EXT:doc/Resources/Private/Templates/Module.html'); |
| 41 | + $view = GeneralUtility::makeInstance(StandaloneView::class); |
| 42 | + $view->setTemplatePathAndFilename($templatePathAndFilename); |
| 43 | + $view->assignMultiple([ |
| 44 | + 'path' => $publicResourcesPath, |
| 45 | + 'docRoothPath' => $docRootPath, |
| 46 | + 'darkMode' => $settings['darkMode'] ?? false |
| 47 | + ]); |
| 48 | + return $view; |
| 49 | + } |
| 50 | +} |
0 commit comments