‪TYPO3CMS  ‪main
AbstractContentObject.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ServerRequestInterface;
26 
31 {
32  protected ?‪PageRenderer ‪$pageRenderer = null;
33 
37  protected ServerRequestInterface ‪$request;
38 
40 
49  abstract public function ‪render($conf = []);
50 
52  {
53  return $this->cObj ?? $this->‪getTypoScriptFrontendController()->cObj;
54  }
55 
56  public function ‪setRequest(ServerRequestInterface ‪$request): void
57  {
58  $this->request = ‪$request;
59  }
60 
62  {
63  $this->cObj = ‪$cObj;
64  // Provide the ContentObjectRenderer to the request as well, for code
65  // that only passes the request to more underlying layers, like Extbase does.
66  // Also makes sure the request in a Fluid RenderingContext also has the current
67  // content object available.
68  $this->request = $this->request->withAttribute('currentContentObject', ‪$cObj);
69  }
70 
71  protected function ‪hasTypoScriptFrontendController(): bool
72  {
73  return $this->cObj?->getTypoScriptFrontendController() instanceof ‪TypoScriptFrontendController;
74  }
75 
80  {
81  if (!$this->‪hasTypoScriptFrontendController()) {
82  throw new ‪ContentRenderingException('TypoScriptFrontendController is not available.', 1655723512);
83  }
84 
85  return $this->cObj->getTypoScriptFrontendController();
86  }
87 
89  {
90  return GeneralUtility::makeInstance(PageRepository::class);
91  }
92 
93  protected function ‪getPageRenderer(): ‪PageRenderer
94  {
95  if ($this->pageRenderer === null) {
96  $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
97  }
98 
100  }
101 }
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\getContentObjectRenderer
‪getContentObjectRenderer()
Definition: AbstractContentObject.php:51
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\$pageRenderer
‪PageRenderer $pageRenderer
Definition: AbstractContentObject.php:32
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\getPageRenderer
‪getPageRenderer()
Definition: AbstractContentObject.php:93
‪TYPO3\CMS\Frontend\ContentObject
Definition: AbstractContentObject.php:18
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\setContentObjectRenderer
‪setContentObjectRenderer(ContentObjectRenderer $cObj)
Definition: AbstractContentObject.php:61
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\getPageRepository
‪getPageRepository()
Definition: AbstractContentObject.php:88
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\$request
‪ServerRequestInterface $request
Definition: AbstractContentObject.php:37
‪TYPO3\CMS\Frontend\ContentObject\Exception\ContentRenderingException
Definition: ContentRenderingException.php:24
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\hasTypoScriptFrontendController
‪hasTypoScriptFrontendController()
Definition: AbstractContentObject.php:71
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:44
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject
Definition: AbstractContentObject.php:31
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\$cObj
‪ContentObjectRenderer $cObj
Definition: AbstractContentObject.php:39
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:82
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\getTypoScriptFrontendController
‪getTypoScriptFrontendController()
Definition: AbstractContentObject.php:79
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\setRequest
‪setRequest(ServerRequestInterface $request)
Definition: AbstractContentObject.php:56
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:102
‪TYPO3\CMS\Core\Domain\Repository\PageRepository
Definition: PageRepository.php:69
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\render
‪string render($conf=[])