1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Extension "sf_event_mgt" for TYPO3 CMS. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the |
9
|
|
|
* LICENSE.txt file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace DERHANSEN\SfEventMgt\Service; |
13
|
|
|
|
14
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
15
|
|
|
use TYPO3\CMS\Core\View\ViewFactoryData; |
|
|
|
|
16
|
|
|
use TYPO3\CMS\Core\View\ViewFactoryInterface; |
17
|
|
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; |
|
|
|
|
18
|
|
|
use TYPO3\CMS\Extbase\Mvc\RequestInterface; |
|
|
|
|
19
|
|
|
use TYPO3\CMS\Fluid\View\FluidViewAdapter; |
|
|
|
|
20
|
|
|
|
21
|
|
|
class FluidRenderingService |
22
|
|
|
{ |
23
|
|
|
public function __construct( |
24
|
|
|
private readonly ConfigurationManagerInterface $configurationManager, |
25
|
|
|
private readonly ViewFactoryInterface $viewFactory |
26
|
|
|
) { |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Renders a Fluid view for the given template |
31
|
|
|
*/ |
32
|
|
|
public function renderTemplate( |
33
|
|
|
RequestInterface $request, |
34
|
|
|
string $template, |
35
|
|
|
array $variables, |
36
|
|
|
string $format = 'html' |
37
|
|
|
): string { |
38
|
|
|
$viewFactoryData = new ViewFactoryData( |
39
|
|
|
templateRootPaths: $this->getTemplateFolders(), |
40
|
|
|
partialRootPaths: $this->getTemplateFolders('partial'), |
41
|
|
|
layoutRootPaths: $this->getTemplateFolders('layout'), |
42
|
|
|
request: $request, |
43
|
|
|
format: $format |
44
|
|
|
); |
45
|
|
|
$view = $this->viewFactory->create($viewFactoryData); |
46
|
|
|
$view->assignMultiple($variables); |
47
|
|
|
return $view->render($template); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Parses the given string with Fluid and decodes the result with html_entity_decode to revert Fluids encoding |
52
|
|
|
* of variables. |
53
|
|
|
* |
54
|
|
|
* Note, the result of this function must never be used as raw/direct output in HTML/frontend context. |
55
|
|
|
*/ |
56
|
|
|
public function parseString(RequestInterface $request, string $string, array $variables = []): string |
57
|
|
|
{ |
58
|
|
|
if ($string === '') { |
59
|
|
|
return ''; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$viewFactoryData = new ViewFactoryData( |
63
|
|
|
request: $request, |
64
|
|
|
); |
65
|
|
|
$view = $this->viewFactory->create($viewFactoryData); |
66
|
|
|
if (!$view instanceof FluidViewAdapter) { |
67
|
|
|
throw new \RuntimeException( |
68
|
|
|
'FluidRenderingService->parseStringFluid() can only deal with Fluid views via FluidViewAdapter', |
69
|
|
|
1727434457 |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
$view->getRenderingContext()->getTemplatePaths()->setTemplateSource($string); |
|
|
|
|
73
|
|
|
$view->assignMultiple($variables); |
74
|
|
|
|
75
|
|
|
return html_entity_decode($view->render()); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Returns the template folders for the given part |
80
|
|
|
*/ |
81
|
|
|
protected function getTemplateFolders(string $part = 'template'): array |
82
|
|
|
{ |
83
|
|
|
$extbaseConfig = $this->configurationManager->getConfiguration( |
84
|
|
|
ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, |
85
|
|
|
'SfEventMgt' |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
if (!empty($extbaseConfig['view'][$part . 'RootPaths'])) { |
89
|
|
|
$templatePaths = $extbaseConfig['view'][$part . 'RootPaths']; |
90
|
|
|
ksort($templatePaths); |
91
|
|
|
} |
92
|
|
|
if (empty($templatePaths) && isset($extbaseConfig['view'])) { |
93
|
|
|
$path = $extbaseConfig['view'][$part . 'RootPath']; |
94
|
|
|
if (!empty($path)) { |
95
|
|
|
$templatePaths = []; |
96
|
|
|
$templatePaths[] = $path; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
if (empty($templatePaths)) { |
100
|
|
|
$templatePaths = []; |
101
|
|
|
$templatePaths[] = 'EXT:sf_event_mgt/Resources/Private/' . ucfirst($part) . 's/'; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$absolutePaths = []; |
105
|
|
|
foreach ($templatePaths as $templatePath) { |
106
|
|
|
$absolutePaths[] = GeneralUtility::getFileAbsFileName($this->ensureSuffixedPath($templatePath)); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return $absolutePaths; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Makes sure the path ends with a slash |
114
|
|
|
*/ |
115
|
|
|
protected function ensureSuffixedPath(string $path): string |
116
|
|
|
{ |
117
|
|
|
return rtrim($path, '/') . '/'; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths