TYPO3 CMS  TYPO3_8-7
RenderingContext.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
31 
35 class RenderingContext extends \TYPO3Fluid\Fluid\Core\Rendering\RenderingContext
36 {
43 
51  protected $objectManager;
52 
58  protected $controllerContext;
59 
66  protected $legacyMode = false;
67 
72  public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
73  {
74  $this->objectManager = $objectManager;
75  }
76 
80  public function injectViewHelperVariableContainer(\TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer $viewHelperVariableContainer)
81  {
82  $this->viewHelperVariableContainer = $viewHelperVariableContainer;
83  }
84 
88  public function __construct(ViewInterface $view = null)
89  {
90  if ($view !== null) {
91  // Note: if $view is received here this indicates internal framework instancing
92  // and it is safe to call the parent constructor. Custom, non-view-providing
93  // usages will only perform the initialisation below (which is sufficient mind you!)
94  parent::__construct($view);
95  } else {
96  // Reproduced partial initialisation from parent::__construct; minus the custom
97  // implementations we attach below.
98  $this->setTemplateParser(new TemplateParser());
99  $this->setTemplateCompiler(new TemplateCompiler());
100  $this->setViewHelperInvoker(new ViewHelperInvoker());
101  $this->setViewHelperVariableContainer(new ViewHelperVariableContainer());
102  }
103 
104  $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
105  $this->setTemplateProcessors(array_map([$objectManager, 'get'], $GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['preProcessors']));
106  $this->setExpressionNodeTypes($GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['expressionNodeTypes']);
107  $this->setTemplatePaths($objectManager->get(TemplatePaths::class));
108  $this->setViewHelperResolver($objectManager->get(ViewHelperResolver::class));
109  $this->setVariableProvider($objectManager->get(CmsVariableProvider::class));
110 
112  $cache = $objectManager->get(CacheManager::class)->getCache('fluid_template');
113  if (is_a($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['fluid_template']['frontend'], FluidTemplateCache::class, true)) {
114  $this->setCache($cache);
115  }
116  }
117 
124  public function buildParserConfiguration()
125  {
126  $parserConfiguration = parent::buildParserConfiguration();
127  if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['interceptors'])) {
128  foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['interceptors'] as $className) {
129  $interceptor = GeneralUtility::makeInstance($className);
130  if (!$interceptor instanceof InterceptorInterface) {
131  throw new \InvalidArgumentException('Interceptor "' . $className . '" needs to implement ' . InterceptorInterface::class . '.', 1462869795);
132  }
133  $parserConfiguration->addInterceptor($interceptor);
134  }
135  }
136 
137  return $parserConfiguration;
138  }
139 
148  public function setLegacyMode($legacyMode)
149  {
151  $this->legacyMode = $legacyMode;
152  }
153 
160  public function getObjectManager()
161  {
162  return $this->objectManager;
163  }
164 
173  {
175  'getTemplateVariableContainer is deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9' .
176  ' - use getVariableProvider instead'
177  );
178  return $this->variableProvider;
179  }
180 
186  public function getControllerContext()
187  {
189  }
190 
194  public function setControllerAction($action)
195  {
196  $dotPosition = strpos($action, '.');
197  if ($dotPosition !== false) {
198  $action = substr($action, 0, $dotPosition);
199  }
200  parent::setControllerAction($action);
201  $this->controllerContext->getRequest()->setControllerActionName(lcfirst($action));
202  }
203 
208  public function setControllerName($controllerName)
209  {
210  parent::setControllerName($controllerName);
211  $this->controllerContext->getRequest()->setControllerName($controllerName);
212  }
213 
219  public function setControllerContext(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext)
220  {
221  $request = $controllerContext->getRequest();
222  $this->controllerContext = $controllerContext;
223  $this->setControllerAction($request->getControllerActionName());
224  // Check if Request is using a sub-package key; in which case we translate this
225  // for our RenderingContext as an emulated plain old sub-namespace controller.
226  $controllerName = $request->getControllerName();
227  if ($request->getControllerSubpackageKey() && !strpos($controllerName, '\\')) {
228  $this->setControllerName($request->getControllerSubpackageKey() . '\\' . $controllerName);
229  } else {
230  $this->setControllerName($controllerName);
231  }
232  }
233 }
static makeInstance($className,... $constructorArguments)
injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
setControllerContext(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext)
injectViewHelperVariableContainer(\TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer $viewHelperVariableContainer)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']