[TASK] BACK_PATH DocumentTemplate
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Be / AbstractBackendViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Be;
3
4 /* *
5 * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * *
12 * This script is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15 * General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with the script. *
19 * If not, see http://www.gnu.org/licenses/lgpl.html *
20 * *
21 * The TYPO3 project - inspiring people to share! *
22 * */
23
24 use TYPO3\CMS\Backend\Template\DocumentTemplate;
25 use TYPO3\CMS\Core\Page\PageRenderer;
26 use TYPO3\CMS\Core\Utility\GeneralUtility;
27 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
28
29 /**
30 * The abstract base class for all backend view helpers
31 * Note: backend view helpers are still experimental!
32 */
33 abstract class AbstractBackendViewHelper extends AbstractViewHelper {
34
35 /**
36 * Gets instance of template if exists or create a new one.
37 * Saves instance in viewHelperVariableContainer
38 *
39 * @return DocumentTemplate $doc
40 */
41 public function getDocInstance() {
42 if ($this->viewHelperVariableContainer->exists(AbstractBackendViewHelper::class, 'DocumentTemplate')) {
43 $doc = $this->viewHelperVariableContainer->get(AbstractBackendViewHelper::class, 'DocumentTemplate');
44 } else {
45 /** @var $doc DocumentTemplate */
46 $doc = GeneralUtility::makeInstance(DocumentTemplate::class);
47 $this->viewHelperVariableContainer->add(AbstractBackendViewHelper::class, 'DocumentTemplate', $doc);
48 }
49
50 return $doc;
51 }
52
53 /**
54 * Gets instance of PageRenderer if exists or create a new one.
55 * Saves instance in viewHelperVariableContainer
56 *
57 * @return PageRenderer
58 */
59 public function getPageRenderer() {
60 if ($this->viewHelperVariableContainer->exists(AbstractBackendViewHelper::class, 'PageRenderer')) {
61 $pageRenderer = $this->viewHelperVariableContainer->get(AbstractBackendViewHelper::class, 'PageRenderer');
62 } else {
63 /** @var $doc DocumentTemplate */
64 $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
65 $this->viewHelperVariableContainer->add(AbstractBackendViewHelper::class, 'PageRenderer', $pageRenderer);
66 }
67
68 return $pageRenderer;
69 }
70 }