‪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;
22 use TYPO3\CMS\Core\Page\PageRenderer;
26 
31 {
32  protected ?PageRenderer ‪$pageRenderer = null;
33 
37  protected ServerRequestInterface ‪$request;
38 
39  protected ?ContentObjectRenderer ‪$cObj = null;
40 
47  abstract public function ‪render($conf = []);
48 
49  public function ‪getContentObjectRenderer(): ContentObjectRenderer
50  {
51  return $this->cObj ?? $this->‪getTypoScriptFrontendController()->cObj;
52  }
53 
54  public function ‪setRequest(ServerRequestInterface ‪$request): void
55  {
56  $this->request = ‪$request;
57  }
58 
59  public function ‪setContentObjectRenderer(ContentObjectRenderer ‪$cObj): void
60  {
61  $this->cObj = ‪$cObj;
62  }
63 
64  protected function ‪hasTypoScriptFrontendController(): bool
65  {
66  return $this->cObj?->getTypoScriptFrontendController() instanceof ‪TypoScriptFrontendController;
67  }
68 
73  {
74  if (!$this->‪hasTypoScriptFrontendController()) {
75  throw new ‪ContentRenderingException('TypoScriptFrontendController is not available.', 1655723512);
76  }
77 
78  return $this->cObj->getTypoScriptFrontendController();
79  }
80 
82  {
83  if (!$this->‪hasTypoScriptFrontendController()) {
84  return GeneralUtility::makeInstance(PageRepository::class);
85  }
87  if (!$this->‪getTypoScriptFrontendController()->sys_page instanceof ‪PageRepository) {
88  return GeneralUtility::makeInstance(
89  PageRepository::class,
90  $this->‪getTypoScriptFrontendController()->getContext()
91  );
92  }
93  return $this->‪getTypoScriptFrontendController()->sys_page;
94  }
95 
96  protected function ‪getPageRenderer(): PageRenderer
97  {
98  if ($this->pageRenderer === null) {
99  $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
100  }
101 
102  return ‪$this->pageRenderer;
103  }
104 }
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\getContentObjectRenderer
‪getContentObjectRenderer()
Definition: AbstractContentObject.php:49
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\$pageRenderer
‪PageRenderer $pageRenderer
Definition: AbstractContentObject.php:32
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\getPageRenderer
‪getPageRenderer()
Definition: AbstractContentObject.php:96
‪TYPO3\CMS\Frontend\ContentObject
Definition: AbstractContentObject.php:18
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\setContentObjectRenderer
‪setContentObjectRenderer(ContentObjectRenderer $cObj)
Definition: AbstractContentObject.php:59
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\getPageRepository
‪getPageRepository()
Definition: AbstractContentObject.php:81
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\$request
‪ServerRequestInterface $request
Definition: AbstractContentObject.php:37
‪TYPO3\CMS\Frontend\ContentObject\Exception\ContentRenderingException
Definition: ContentRenderingException.php:25
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\hasTypoScriptFrontendController
‪hasTypoScriptFrontendController()
Definition: AbstractContentObject.php:64
‪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:105
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\getTypoScriptFrontendController
‪getTypoScriptFrontendController()
Definition: AbstractContentObject.php:72
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\setRequest
‪setRequest(ServerRequestInterface $request)
Definition: AbstractContentObject.php:54
‪TYPO3\CMS\Core\Domain\Repository\PageRepository
Definition: PageRepository.php:63
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Frontend\ContentObject\AbstractContentObject\render
‪string render($conf=[])