1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Content Controller. |
5
|
|
|
*/ |
6
|
|
|
declare(strict_types = 1); |
7
|
|
|
|
8
|
|
|
namespace HDNET\Autoloader\Controller; |
9
|
|
|
|
10
|
|
|
use HDNET\Autoloader\Utility\ClassNamingUtility; |
11
|
|
|
use HDNET\Autoloader\Utility\ExtendedUtility; |
12
|
|
|
use HDNET\Autoloader\Utility\ModelUtility; |
13
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
14
|
|
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; |
15
|
|
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; |
16
|
|
|
use TYPO3\CMS\Fluid\View\StandaloneView; |
17
|
|
|
use TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Content Controller. |
21
|
|
|
*/ |
22
|
|
|
class ContentController extends ActionController |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Render the content Element via ExtBase. |
26
|
|
|
*/ |
27
|
|
|
public function indexAction() |
28
|
|
|
{ |
29
|
|
|
try { |
30
|
|
|
$extensionKey = $this->settings['extensionKey']; |
31
|
|
|
$vendorName = $this->settings['vendorName']; |
32
|
|
|
$name = $this->settings['contentElement']; |
33
|
|
|
$data = $this->configurationManager->getContentObject()->data; |
34
|
|
|
|
35
|
|
|
$targetObject = ClassNamingUtility::getFqnByPath($vendorName, $extensionKey, 'Domain/Model/Content/' . $name); |
36
|
|
|
$model = ModelUtility::getModel($targetObject, $data); |
37
|
|
|
|
38
|
|
|
/** @var StandaloneView $view */ |
39
|
|
|
$view = ExtendedUtility::create(StandaloneView::class); |
40
|
|
|
$context = $view->getRenderingContext(); |
41
|
|
|
$context->setControllerName('Content'); |
42
|
|
|
$context->setControllerAction($this->settings['contentElement']); |
43
|
|
|
$view->setRenderingContext($context); |
44
|
|
|
|
45
|
|
|
$configuration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK); |
46
|
|
|
|
47
|
|
|
// add dataprocessors |
48
|
|
|
$contentDataProcessor = GeneralUtility::makeInstance(ContentDataProcessor::class); |
49
|
|
|
$variables = $contentDataProcessor->process( |
50
|
|
|
$this->configurationManager->getContentObject(), |
51
|
|
|
['dataProcessing.' => $this->settings['dataProcessing']], |
52
|
|
|
['data' => $data] |
53
|
|
|
); |
54
|
|
|
$variables['settings'] = $this->settings; |
55
|
|
|
$variables['object'] = $model; |
56
|
|
|
|
57
|
|
|
$viewConfiguration = $configuration['view']; |
58
|
|
|
|
59
|
|
|
$layoutRootPaths = \is_array($viewConfiguration['layoutRootPaths']) ? $viewConfiguration['layoutRootPaths'] : []; |
60
|
|
|
if (!isset($layoutRootPaths[5])) { |
61
|
|
|
$layoutRootPaths[5] = 'EXT:' . $this->settings['extensionKey'] . '/Resources/Private/Layouts/'; |
62
|
|
|
} |
63
|
|
|
$view->setLayoutRootPaths($layoutRootPaths); |
64
|
|
|
|
65
|
|
|
$partialRootPaths = \is_array($viewConfiguration['partialRootPaths']) ? $viewConfiguration['partialRootPaths'] : []; |
66
|
|
|
if (!isset($partialRootPaths[5])) { |
67
|
|
|
$partialRootPaths[5] = 'EXT:' . $this->settings['extensionKey'] . '/Resources/Private/Partials/'; |
68
|
|
|
} |
69
|
|
|
$view->setPartialRootPaths($partialRootPaths); |
70
|
|
|
|
71
|
|
|
$templateRootPaths = \is_array($viewConfiguration['templateRootPaths']) ? $viewConfiguration['templateRootPaths'] : []; |
72
|
|
|
if (!isset($templateRootPaths[5])) { |
73
|
|
|
$templateRootPaths[5] = 'EXT:' . $this->settings['extensionKey'] . '/Resources/Private/Templates/'; |
74
|
|
|
} |
75
|
|
|
$view->setTemplateRootPaths($templateRootPaths); |
76
|
|
|
|
77
|
|
|
$view->assignMultiple( |
78
|
|
|
$variables |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
return $view->render(); |
82
|
|
|
} catch (\Exception $ex) { |
83
|
|
|
return 'Exception in content rendering: ' . $ex->getMessage(); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|