StandaloneTemplateRenderer::renderTemplate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 3
b 0
f 0
nc 1
nop 3
dl 0
loc 11
rs 10
1
<?php
2
namespace Qbus\Qbtools\Utility;
3
4
use TYPO3\CMS\Core\Utility\GeneralUtility;
5
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
6
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
7
use TYPO3\CMS\Fluid\View\StandaloneView;
8
9
/***************************************************************
10
 *  Copyright notice
11
 *
12
 *  (c) 2013 Axel Wüstemann <[email protected]>, Qbus Werbeagentur GmbH
13
 *
14
 *  All rights reserved
15
 *
16
 *  This script is part of the TYPO3 project. The TYPO3 project is
17
 *  free software; you can redistribute it and/or modify
18
 *  it under the terms of the GNU General Public License as published by
19
 *  the Free Software Foundation; either version 3 of the License, or
20
 *  (at your option) any later version.
21
 *
22
 *  The GNU General Public License can be found at
23
 *  http://www.gnu.org/copyleft/gpl.html.
24
 *
25
 *  This script is distributed in the hope that it will be useful,
26
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
 *  GNU General Public License for more details.
29
 *
30
 *  This copyright notice MUST APPEAR in all copies of the script!
31
 ***************************************************************/
32
33
/**
34
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
35
 */
36
class StandaloneTemplateRenderer
37
{
38
    /**
39
     * @var ConfigurationManagerInterface
40
     */
41
    protected $configurationManager;
42
43
    /**
44
     * @var ObjectManagerInterface
45
     */
46
    protected $objectManager;
47
48
    /**
49
     * @param  ConfigurationManagerInterface $configurationManager
50
     * @return void
51
     */
52
    public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager)
53
    {
54
        $this->configurationManager = $configurationManager;
55
    }
56
57
    /**
58
     * @param  ObjectManagerInterface $objectManager
59
     * @return void
60
     */
61
    public function injectObjectManager(ObjectManagerInterface $objectManager)
62
    {
63
        $this->objectManager = $objectManager;
64
    }
65
66
    /**
67
     * returns a rendered standalone template
68
     *
69
     * @param  string $templatePath the template path relative to templateRootPath (UpperCamelCase)
70
     * @param  array  $variables    variables to be passed to the Fluid view
71
     * @param  string $rootPath     the template path relative to templateRootPath (UpperCamelCase)
72
     * @return string
73
     */
74
    public function renderTemplate($template, $variables, $rootPath)
75
    {
76
        /** @var StandaloneView $view */
77
        $view = $this->objectManager->get(StandaloneView::class);
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\CMS\Extbase\Object...ManagerInterface::get() has been deprecated: since TYPO3 10.4, will be removed in version 12.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

77
        $view = /** @scrutinizer ignore-deprecated */ $this->objectManager->get(StandaloneView::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
78
79
        $view->setLayoutRootPaths([$rootPath  . '/Layouts']);
80
        $view->setPartialRootPaths([$rootPath . '/Partials']);
81
        $view->setTemplatePathAndFilename($rootPath . '/Templates/' . $template);
82
        $view->assignMultiple($variables);
83
84
        return $view->render();
85
    }
86
87
    /**
88
     * returns a standalone template
89
     *
90
     * @param  string                              $templatePath the template path relative to templateRootPath (UpperCamelCase)
91
     * @return StandaloneView
92
     */
93
    public function buildTemplate($templatePath)
94
    {
95
        /** @var StandaloneView $view */
96
        $view = $this->objectManager->get(StandaloneView::class);
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\CMS\Extbase\Object...ManagerInterface::get() has been deprecated: since TYPO3 10.4, will be removed in version 12.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

96
        $view = /** @scrutinizer ignore-deprecated */ $this->objectManager->get(StandaloneView::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
97
98
        $extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
99
        $templateRootPath = GeneralUtility::getFileAbsFileName($extbaseFrameworkConfiguration['view']['templateRootPath']);
100
        $templatePathAndFilename = $templateRootPath . $templatePath;
101
        $view->setTemplatePathAndFilename($templatePathAndFilename);
102
103
        return $view;
104
    }
105
}
106