‪TYPO3CMS  10.4
StandaloneView.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
16 namespace ‪TYPO3\CMS\Fluid\View;
17 
27 use TYPO3Fluid\Fluid\View\Exception\InvalidTemplateResourceException;
28 
34 {
38  protected ‪$objectManager;
39 
47  public function ‪__construct(‪ContentObjectRenderer $contentObject = null)
48  {
49  $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
50 
52  $configurationManager = $this->objectManager->get(ConfigurationManagerInterface::class);
53  if ($contentObject === null) {
55  $contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
56  }
57  $configurationManager->setContentObject($contentObject);
58 
59  $baseUri = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
60  if ($this->objectManager->get(EnvironmentService::class)->isEnvironmentInBackendMode()) {
61  $baseUri .= TYPO3_mainDir;
62  }
63 
65  $request = $this->objectManager->get(Request::class);
66  $request->setRequestUri(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'));
67  $request->setBaseUri($baseUri);
69  $uriBuilder = $this->objectManager->get(UriBuilder::class);
70  $uriBuilder->setRequest($request);
72  ‪$controllerContext = $this->objectManager->get(ControllerContext::class);
75  $renderingContext = $this->objectManager->get(RenderingContext::class, $this);
76  $renderingContext->setControllerContext(‪$controllerContext);
77  parent::__construct($renderingContext);
78  }
79 
86  public function ‪setFormat($format)
87  {
88  if ($this->baseRenderingContext instanceof ‪RenderingContext) {
89  $this->baseRenderingContext->getControllerContext()->getRequest()->setFormat($format);
90  $this->baseRenderingContext->getTemplatePaths()->setFormat($format);
91  } else {
92  throw new \RuntimeException('The rendering context must be of type ' . RenderingContext::class, 1482251886);
93  }
94  }
95 
102  public function ‪getFormat()
103  {
104  if ($this->baseRenderingContext instanceof ‪RenderingContext) {
105  return $this->baseRenderingContext->getControllerContext()->getRequest()->getFormat();
106  }
107  throw new \RuntimeException('The rendering context must be of type ' . RenderingContext::class, 1482251887);
108  }
109 
117  public function ‪getRequest()
118  {
119  if ($this->baseRenderingContext instanceof ‪RenderingContext) {
120  return $this->baseRenderingContext->getControllerContext()->getRequest();
121  }
122  throw new \RuntimeException('The rendering context must be of type ' . RenderingContext::class, 1482251888);
123  }
124 
134  public function ‪getTemplatePathAndFilename()
135  {
136  $templatePaths = $this->baseRenderingContext->getTemplatePaths();
137  return $templatePaths->resolveTemplateFileForControllerAndActionAndFormat(
138  $this->baseRenderingContext->getControllerName(),
139  $this->baseRenderingContext->getControllerAction(),
140  $templatePaths->getFormat()
141  );
142  }
143 
150  public function ‪setTemplateSource($templateSource)
151  {
152  $this->baseRenderingContext->getTemplatePaths()->setTemplateSource($templateSource);
153  }
154 
160  public function ‪hasTemplate()
161  {
162  try {
163  $this->baseRenderingContext->getTemplatePaths()->getTemplateSource(
164  $this->baseRenderingContext->getControllerName(),
165  $this->baseRenderingContext->getControllerAction()
166  );
167  return true;
168  } catch (InvalidTemplateResourceException $e) {
169  return false;
170  }
171  }
172 }
‪TYPO3\CMS\Fluid\View\StandaloneView\setTemplateSource
‪setTemplateSource($templateSource)
Definition: StandaloneView.php:149
‪TYPO3\CMS\Fluid\View\StandaloneView\__construct
‪__construct(ContentObjectRenderer $contentObject=null)
Definition: StandaloneView.php:46
‪TYPO3\CMS\Fluid\View\StandaloneView\$objectManager
‪ObjectManager null $objectManager
Definition: StandaloneView.php:37
‪TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
Definition: UriBuilder.php:39
‪TYPO3\CMS\Fluid\View\StandaloneView\hasTemplate
‪bool hasTemplate()
Definition: StandaloneView.php:159
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\$controllerContext
‪TYPO3 CMS Extbase Mvc Controller ControllerContext $controllerContext
Definition: AbstractTemplateView.php:36
‪TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext
Definition: ControllerContext.php:28
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:28
‪TYPO3\CMS\Fluid\View\AbstractTemplateView
Definition: AbstractTemplateView.php:33
‪TYPO3\CMS\Fluid\View\StandaloneView\getRequest
‪TYPO3 CMS Extbase Mvc Request getRequest()
Definition: StandaloneView.php:116
‪TYPO3\CMS\Fluid\View\StandaloneView\getFormat
‪string getFormat()
Definition: StandaloneView.php:101
‪TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext\setUriBuilder
‪setUriBuilder(UriBuilder $uriBuilder)
Definition: ControllerContext.php:136
‪TYPO3\CMS\Fluid\View\StandaloneView\setFormat
‪setFormat($format)
Definition: StandaloneView.php:85
‪TYPO3\CMS\Extbase\Mvc\Web\Request
Definition: Request.php:23
‪TYPO3\CMS\Extbase\Service\EnvironmentService
Definition: EnvironmentService.php:27
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:97
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext
Definition: RenderingContext.php:39
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28
‪TYPO3\CMS\Fluid\View
Definition: AbstractTemplateView.php:16
‪TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext\setRequest
‪setRequest(Request $request)
Definition: ControllerContext.php:78
‪TYPO3\CMS\Fluid\View\StandaloneView\getTemplatePathAndFilename
‪string getTemplatePathAndFilename()
Definition: StandaloneView.php:133