[CLEANUP] Rework/simplify copyright header and remove @package
[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 file is part of the TYPO3 CMS project.
6 *
7 * It is backported from the TYPO3 Flow package "TYPO3.Fluid".
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use TYPO3\CMS\Backend\Template\DocumentTemplate;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
22
23 /**
24 * The abstract base class for all backend view helpers
25 * Note: backend view helpers are still experimental!
26 */
27 abstract class AbstractBackendViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
28
29 /**
30 * Gets instance of template if exists or create a new one.
31 * Saves instance in viewHelperVariableContainer
32 *
33 * @return \TYPO3\CMS\Backend\Template\DocumentTemplate $doc
34 */
35 public function getDocInstance() {
36 if ($this->viewHelperVariableContainer->exists(
37 'TYPO3\\CMS\\Fluid\\ViewHelpers\\Be\\AbstractBackendViewHelper',
38 'DocumentTemplate'
39 )
40 ) {
41 $doc = $this->viewHelperVariableContainer->get(
42 'TYPO3\\CMS\\Fluid\\ViewHelpers\\Be\\AbstractBackendViewHelper',
43 'DocumentTemplate'
44 );
45 } else {
46 /** @var $doc \TYPO3\CMS\Backend\Template\DocumentTemplate */
47 $doc = $this->createDocInstance();
48 $doc->backPath = $GLOBALS['BACK_PATH'];
49 $this->viewHelperVariableContainer->add(
50 'TYPO3\\CMS\\Fluid\\ViewHelpers\\Be\\AbstractBackendViewHelper',
51 'DocumentTemplate',
52 $doc
53 );
54 }
55
56 return $doc;
57 }
58
59 /**
60 * Other extensions may rely on the fact that $GLOBALS['SOBE'] exists and holds
61 * the DocumentTemplate instance. We should really get rid of this, but for now, let's be backwards compatible.
62 * Relying on $GLOBALS['SOBE'] is @deprecated since 6.0 and will be removed in 6.2 Instead ->getDocInstance() should be used.
63 *
64 * If $GLOBALS['SOBE']->doc holds an instance of \TYPO3\CMS\Backend\Template\DocumentTemplate we reuse it,
65 * if not we create a new one.
66 *
67 * Relying on $GLOBALS['SOBE'] is
68 * @deprecated since 6.0 and will be removed in 6.2 ->getDocInstance() should be used instead.
69 *
70 * @return \TYPO3\CMS\Backend\Template\DocumentTemplate
71 */
72 protected function createDocInstance() {
73 if (
74 isset($GLOBALS['SOBE']) &&
75 is_object($GLOBALS['SOBE']) &&
76 isset($GLOBALS['SOBE']->doc) &&
77 $GLOBALS['SOBE']->doc instanceof \TYPO3\CMS\Backend\Template\DocumentTemplate
78 ) {
79 GeneralUtility::deprecationLog('Usage of $GLOBALS[\'SOBE\'] is deprecated since 6.0 and will be removed in 6.2 ->getDocInstance() should be used instead');
80 $doc = $GLOBALS['SOBE']->doc;
81 } else {
82 $doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
83 if (!isset($GLOBALS['SOBE'])) {
84 $GLOBALS['SOBE'] = new \stdClass();
85 }
86 if (!isset($GLOBALS['SOBE']->doc)) {
87 $GLOBALS['SOBE']->doc = $doc;
88 }
89 }
90
91 return $doc;
92 }
93 }