Completed
Push — master ( f684e7...866dcf )
by Tim
02:11
created

ContentController::createStandaloneView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 0
cp 0
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Content Controller.
4
 */
5
6
namespace HDNET\Autoloader\Controller;
7
8
use HDNET\Autoloader\Utility\ClassNamingUtility;
9
use HDNET\Autoloader\Utility\ExtendedUtility;
10
use HDNET\Autoloader\Utility\ModelUtility;
11
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
12
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
13
use TYPO3\CMS\Fluid\View\StandaloneView;
14
15
/**
16
 * Content Controller.
17
 */
18
class ContentController extends ActionController
19
{
20
    /**
21
     * Render the content Element via ExtBase.
22
     */
23
    public function indexAction()
24
    {
25
        $extensionKey = $this->settings['extensionKey'];
26
        $vendorName = $this->settings['vendorName'];
27
        $name = $this->settings['contentElement'];
28
        $data = $this->configurationManager->getContentObject()->data;
29
30
        $targetObject = ClassNamingUtility::getFqnByPath($vendorName, $extensionKey, 'Domain/Model/Content/' . $name);
31
        $model = ModelUtility::getModel($targetObject, $data);
32
33
        /** @var StandaloneView $view */
34
        $view = ExtendedUtility::create(StandaloneView::class);
35
        $context = $view->getRenderingContext();
36
        $context->setControllerName('Content');
37
        $context->setControllerAction($this->settings['contentElement'] . '/Test');
38
        $view->setRenderingContext($context);
39
40
        $configuration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
41
        $viewConfiguration = $configuration['view'];
42
43
        $layoutRootPaths = is_array($viewConfiguration['layoutRootPaths']) ? $viewConfiguration['layoutRootPaths'] : [];
44
        $layoutRootPaths[5] = 'EXT:' . $this->settings['extensionKey'] . '/Resources/Private/Layouts/';
45
        $view->setLayoutRootPaths($layoutRootPaths);
46
47
        $partialRootPaths = is_array($viewConfiguration['partialRootPaths']) ? $viewConfiguration['partialRootPaths'] : [];
48
        $partialRootPaths[5] = 'EXT:' . $this->settings['extensionKey'] . '/Resources/Private/Partials/';
49
        $view->setPartialRootPaths($partialRootPaths);
50
51
        $templateRootPaths = is_array($viewConfiguration['templateRootPaths']) ? $viewConfiguration['templateRootPaths'] : [];
52
        $templateRootPaths[5] = 'EXT:' . $this->settings['extensionKey'] . '/Resources/Private/Templates/';
53
        $view->setTemplateRootPaths($templateRootPaths);
54
55
        $view->assignMultiple([
56
            'data' => $data,
57
            'object' => $model,
58
            'settings' => $this->settings,
59
        ]);
60
61
        return $view->render();
62
    }
63
}
64