TYPO3 CMS  TYPO3_6-2
CObjectViewHelper.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is part of the TYPO3 project - inspiring people to share! *
6  * *
7  * TYPO3 is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU General Public License version 2 as published by *
9  * the Free Software Foundation. *
10  * *
11  * This script is distributed in the hope that it will be useful, but *
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
14  * Public License for more details. *
15  * */
43 
50  protected $escapingInterceptorEnabled = FALSE;
51 
55  protected $typoScriptSetup;
56 
60  protected $tsfeBackup;
61 
66 
71  public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager) {
72  $this->configurationManager = $configurationManager;
73  $this->typoScriptSetup = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
74  }
75 
86  public function render($typoscriptObjectPath, $data = NULL, $currentValueKey = NULL, $table = '') {
87  if (TYPO3_MODE === 'BE') {
89  }
90  if ($data === NULL) {
91  $data = $this->renderChildren();
92  }
93  $currentValue = NULL;
94  if (is_object($data)) {
96  } elseif (is_string($data) || is_numeric($data)) {
97  $currentValue = (string) $data;
98  $data = array($data);
99  }
101  $contentObject = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
102  $contentObject->start($data, $table);
103  if ($currentValue !== NULL) {
104  $contentObject->setCurrentVal($currentValue);
105  } elseif ($currentValueKey !== NULL && isset($data[$currentValueKey])) {
106  $contentObject->setCurrentVal($data[$currentValueKey]);
107  }
108  $pathSegments = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('.', $typoscriptObjectPath);
109  $lastSegment = array_pop($pathSegments);
110  $setup = $this->typoScriptSetup;
111  foreach ($pathSegments as $segment) {
112  if (!array_key_exists(($segment . '.'), $setup)) {
113  throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('TypoScript object path "' . htmlspecialchars($typoscriptObjectPath) . '" does not exist', 1253191023);
114  }
115  $setup = $setup[$segment . '.'];
116  }
117  $content = $contentObject->cObjGetSingle($setup[$lastSegment], $setup[$lastSegment . '.']);
118  if (TYPO3_MODE === 'BE') {
119  $this->resetFrontendEnvironment();
120  }
121  return $content;
122  }
123 
130  protected function simulateFrontendEnvironment() {
131  $this->tsfeBackup = isset($GLOBALS['TSFE']) ? $GLOBALS['TSFE'] : NULL;
132  $GLOBALS['TSFE'] = new \stdClass();
133  $GLOBALS['TSFE']->cObjectDepthCounter = 100;
134  }
135 
142  protected function resetFrontendEnvironment() {
143  $GLOBALS['TSFE'] = $this->tsfeBackup;
144  }
145 }
const TYPO3_MODE
Definition: init.php:40
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)