‪TYPO3CMS  11.5
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 
23 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
24 use TYPO3Fluid\Fluid\View\Exception\InvalidTemplateResourceException;
25 
31 {
39  public function ‪__construct(?ContentObjectRenderer $contentObject = null)
40  {
41  // @deprecated since v11, will be removed with v12. Drop $contentObject argument and ConfigurationManager handling.
42  $configurationManager = GeneralUtility::getContainer()->get(ConfigurationManager::class);
43  if ($contentObject !== null) {
44  trigger_error('Argument $contentObject of class ' . __CLASS__ . ' is deprecated since v11, will be removed with v12.', E_USER_DEPRECATED);
45  } else {
46  $contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
47  }
48  $configurationManager->setContentObject($contentObject);
49 
50  $request = GeneralUtility::makeInstance(Request::class);
51  $renderingContext = GeneralUtility::makeInstance(RenderingContextFactory::class)->create();
52  $renderingContext->setRequest($request);
53  parent::__construct($renderingContext);
54  }
55 
62  public function ‪setFormat($format)
63  {
64  if ($this->baseRenderingContext instanceof ‪RenderingContext) {
65  $this->baseRenderingContext->getRequest()->setFormat($format);
66  $this->baseRenderingContext->getTemplatePaths()->setFormat($format);
67  } else {
68  throw new \RuntimeException('The rendering context must be of type ' . RenderingContext::class, 1482251886);
69  }
70  }
71 
78  public function ‪getFormat()
79  {
80  if ($this->baseRenderingContext instanceof ‪RenderingContext) {
81  return $this->baseRenderingContext->getRequest()->getFormat();
82  }
83  throw new \RuntimeException('The rendering context must be of type ' . RenderingContext::class, 1482251887);
84  }
85 
93  public function ‪getRequest()
94  {
95  if ($this->baseRenderingContext instanceof ‪RenderingContext) {
96  return $this->baseRenderingContext->getRequest();
97  }
98  throw new \RuntimeException('The rendering context must be of type ' . RenderingContext::class, 1482251888);
99  }
100 
111  {
112  $templatePaths = $this->baseRenderingContext->getTemplatePaths();
113  return $templatePaths->resolveTemplateFileForControllerAndActionAndFormat(
114  $this->baseRenderingContext->getControllerName(),
115  $this->baseRenderingContext->getControllerAction(),
116  $templatePaths->getFormat()
117  );
118  }
119 
126  public function ‪setTemplateSource($templateSource)
127  {
128  $this->baseRenderingContext->getTemplatePaths()->setTemplateSource($templateSource);
129  }
130 
136  public function ‪hasTemplate()
137  {
138  try {
139  $this->baseRenderingContext->getTemplatePaths()->getTemplateSource(
140  $this->baseRenderingContext->getControllerName(),
141  $this->baseRenderingContext->getControllerAction()
142  );
143  return true;
144  } catch (InvalidTemplateResourceException $e) {
145  return false;
146  }
147  }
148 }
‪TYPO3\CMS\Fluid\View\StandaloneView\setTemplateSource
‪setTemplateSource($templateSource)
Definition: StandaloneView.php:126
‪TYPO3\CMS\Fluid\View\StandaloneView\__construct
‪__construct(?ContentObjectRenderer $contentObject=null)
Definition: StandaloneView.php:39
‪TYPO3\CMS\Fluid\View\StandaloneView\hasTemplate
‪bool hasTemplate()
Definition: StandaloneView.php:136
‪TYPO3\CMS\Fluid\View\AbstractTemplateView
Definition: AbstractTemplateView.php:35
‪TYPO3\CMS\Fluid\View\StandaloneView\getRequest
‪TYPO3 CMS Extbase Mvc Request getRequest()
Definition: StandaloneView.php:93
‪TYPO3\CMS\Fluid\View\StandaloneView\getFormat
‪string getFormat()
Definition: StandaloneView.php:78
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager
Definition: ConfigurationManager.php:33
‪TYPO3\CMS\Fluid\View\StandaloneView\setFormat
‪setFormat($format)
Definition: StandaloneView.php:62
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:31
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory
Definition: RenderingContextFactory.php:51
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext
Definition: RenderingContext.php:37
‪TYPO3\CMS\Fluid\View
Definition: AbstractTemplateView.php:16
‪TYPO3\CMS\Extbase\Mvc\Request
Definition: Request.php:39
‪TYPO3\CMS\Fluid\View\StandaloneView\getTemplatePathAndFilename
‪string getTemplatePathAndFilename()
Definition: StandaloneView.php:110