Revert "[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 use \TYPO3\CMS\Core\Utility\GeneralUtility;
5
6 /* *
7 * This script 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 Lesser General Public License, either version 3 *
11 * of the License, or (at your option) any later version. *
12 * *
13 * *
14 * This script is distributed in the hope that it will be useful, but *
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
16 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
17 * General Public License for more details. *
18 * *
19 * You should have received a copy of the GNU Lesser General Public *
20 * License along with the script. *
21 * If not, see http://www.gnu.org/licenses/lgpl.html *
22 * *
23 * The TYPO3 project - inspiring people to share! *
24 * */
25 /**
26 * The abstract base class for all backend view helpers
27 * Note: backend view helpers are still experimental!
28 */
29 abstract class AbstractBackendViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
30
31 /**
32 * Gets instance of template if exists or create a new one.
33 * Saves instance in viewHelperVariableContainer
34 *
35 * @return \TYPO3\CMS\Backend\Template\DocumentTemplate $doc
36 */
37 public function getDocInstance() {
38 if ($this->viewHelperVariableContainer->exists(
39 'TYPO3\\CMS\\Fluid\\ViewHelpers\\Be\\AbstractBackendViewHelper',
40 'DocumentTemplate'
41 )
42 ) {
43 $doc = $this->viewHelperVariableContainer->get(
44 'TYPO3\\CMS\\Fluid\\ViewHelpers\\Be\\AbstractBackendViewHelper',
45 'DocumentTemplate'
46 );
47 } else {
48 /** @var $doc \TYPO3\CMS\Backend\Template\DocumentTemplate */
49 $doc = $this->createDocInstance();
50 $doc->backPath = $GLOBALS['BACK_PATH'];
51 $this->viewHelperVariableContainer->add(
52 'TYPO3\\CMS\\Fluid\\ViewHelpers\\Be\\AbstractBackendViewHelper',
53 'DocumentTemplate',
54 $doc
55 );
56 }
57
58 return $doc;
59 }
60
61 /**
62 * Other extensions may rely on the fact that $GLOBALS['SOBE'] exists and holds
63 * the DocumentTemplate instance. We should really get rid of this, but for now, let's be backwards compatible.
64 * Relying on $GLOBALS['SOBE'] is @deprecated since 6.0 and will be removed in 6.2 Instead ->getDocInstance() should be used.
65 *
66 * If $GLOBALS['SOBE']->doc holds an instance of \TYPO3\CMS\Backend\Template\DocumentTemplate we reuse it,
67 * if not we create a new one.
68 *
69 * Relying on $GLOBALS['SOBE'] is
70 * @deprecated since 6.0 and will be removed in 6.2 ->getDocInstance() should be used instead.
71 *
72 * @return \TYPO3\CMS\Backend\Template\DocumentTemplate
73 */
74 protected function createDocInstance() {
75 if (
76 isset($GLOBALS['SOBE']) &&
77 is_object($GLOBALS['SOBE']) &&
78 isset($GLOBALS['SOBE']->doc) &&
79 $GLOBALS['SOBE']->doc instanceof \TYPO3\CMS\Backend\Template\DocumentTemplate
80 ) {
81 GeneralUtility::deprecationLog('Usage of $GLOBALS[\'SOBE\'] is deprecated since 6.0 and will be removed in 6.2 ->getDocInstance() should be used instead');
82 $doc = $GLOBALS['SOBE']->doc;
83 } else {
84 $doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
85 if (!isset($GLOBALS['SOBE'])) {
86 $GLOBALS['SOBE'] = new \stdClass();
87 }
88 if (!isset($GLOBALS['SOBE']->doc)) {
89 $GLOBALS['SOBE']->doc = $doc;
90 }
91 }
92
93 return $doc;
94 }
95 }