‪TYPO3CMS  9.5
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 
20 use TYPO3\CMS\Fluid\Core\Cache\FluidTemplateCache;
24 use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
25 use TYPO3Fluid\Fluid\Core\Parser\Configuration;
26 use TYPO3Fluid\Fluid\Core\Parser\TemplateParser;
27 use TYPO3Fluid\Fluid\Core\Variables\StandardVariableProvider;
28 use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInvoker;
29 use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
30 use TYPO3Fluid\Fluid\View\ViewInterface;
31 
35 class ‪RenderingContext extends \TYPO3Fluid\Fluid\Core\Rendering\RenderingContext
36 {
42  protected ‪$controllerContext;
43 
47  public function ‪injectViewHelperVariableContainer(\‪TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer $viewHelperVariableContainer)
48  {
49  $this->viewHelperVariableContainer = $viewHelperVariableContainer;
50  }
51 
55  public function ‪__construct(ViewInterface $view = null)
56  {
57  if ($view !== null) {
58  // Note: if $view is received here this indicates internal framework instancing
59  // and it is safe to call the parent constructor. Custom, non-view-providing
60  // usages will only perform the initialisation below (which is sufficient mind you!)
61  parent::__construct($view);
62  } else {
63  // Reproduced partial initialisation from parent::__construct; minus the custom
64  // implementations we attach below.
65  $this->setTemplateParser(new TemplateParser());
66  $this->setTemplateCompiler(new TemplateCompiler());
67  $this->setViewHelperInvoker(new ViewHelperInvoker());
68  $this->setViewHelperVariableContainer(new ViewHelperVariableContainer());
69  $this->setVariableProvider(new StandardVariableProvider());
70  }
71 
72  $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
73  $this->setTemplateProcessors(array_map([$objectManager, 'get'], ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['preProcessors']));
74  $this->setExpressionNodeTypes(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['expressionNodeTypes']);
75  $this->setTemplatePaths($objectManager->get(TemplatePaths::class));
76  $this->setViewHelperResolver($objectManager->get(ViewHelperResolver::class));
77 
79  $cache = $objectManager->get(CacheManager::class)->getCache('fluid_template');
80  if (is_a(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['fluid_template']['frontend'], FluidTemplateCache::class, true)) {
81  $this->setCache($cache);
82  }
83  }
84 
91  public function ‪buildParserConfiguration()
92  {
93  $parserConfiguration = parent::buildParserConfiguration();
94  if (!empty(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['interceptors'])) {
95  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['interceptors'] as $className) {
96  $interceptor = GeneralUtility::makeInstance($className);
97  if (!$interceptor instanceof ‪InterceptorInterface) {
98  throw new \InvalidArgumentException('Interceptor "' . $className . '" needs to implement ' . InterceptorInterface::class . '.', 1462869795);
99  }
100  $parserConfiguration->addInterceptor($interceptor);
101  }
102  }
103 
104  return $parserConfiguration;
105  }
106 
112  public function ‪getControllerContext()
113  {
115  }
116 
120  public function ‪setControllerAction($action)
121  {
122  $dotPosition = strpos($action, '.');
123  if ($dotPosition !== false) {
124  $action = substr($action, 0, $dotPosition);
125  }
126  parent::setControllerAction($action);
127  $this->controllerContext->getRequest()->setControllerActionName(lcfirst($action));
128  }
129 
134  public function ‪setControllerName($controllerName)
135  {
136  parent::setControllerName($controllerName);
137  $this->controllerContext->getRequest()->setControllerName($controllerName);
138  }
139 
145  public function ‪setControllerContext(\‪TYPO3\CMS\‪Extbase\Mvc\Controller\ControllerContext ‪$controllerContext)
146  {
147  $request = ‪$controllerContext->getRequest();
148  $this->controllerContext = ‪$controllerContext;
149  $this->‪setControllerAction($request->getControllerActionName());
150  // Check if Request is using a sub-package key; in which case we translate this
151  // for our RenderingContext as an emulated plain old sub-namespace controller.
152  $controllerName = $request->getControllerName();
153  if ($request->getControllerSubpackageKey() && !strpos($controllerName, '\\')) {
154  $this->‪setControllerName($request->getControllerSubpackageKey() . '\\' . $controllerName);
155  } else {
156  $this->‪setControllerName($controllerName);
157  }
158  }
159 }
‪TYPO3\CMS\Fluid\View\TemplatePaths
Definition: TemplatePaths.php:34
‪TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperResolver
Definition: ViewHelperResolver.php:52
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3Fluid
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\setControllerAction
‪setControllerAction($action)
Definition: RenderingContext.php:119
‪TYPO3
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\$controllerContext
‪TYPO3 CMS Extbase Mvc Controller ControllerContext $controllerContext
Definition: RenderingContext.php:41
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\setControllerName
‪setControllerName($controllerName)
Definition: RenderingContext.php:133
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\setControllerContext
‪setControllerContext(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext)
Definition: RenderingContext.php:144
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\buildParserConfiguration
‪Configuration buildParserConfiguration()
Definition: RenderingContext.php:90
‪TYPO3\CMS\Fluid\Core\Parser\InterceptorInterface
Definition: LegacyClassesForIde.php:8
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\__construct
‪__construct(ViewInterface $view=null)
Definition: RenderingContext.php:54
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\getControllerContext
‪TYPO3 CMS Extbase Mvc Controller ControllerContext getControllerContext()
Definition: RenderingContext.php:111
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext\injectViewHelperVariableContainer
‪injectViewHelperVariableContainer(\TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer $viewHelperVariableContainer)
Definition: RenderingContext.php:46
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\Fluid\Core\Rendering
Definition: RenderingContext.php:2
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext
Definition: RenderingContext.php:36
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25