TYPO3 CMS  TYPO3_7-6
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  {
73  $this->configurationManager = $configurationManager;
74  $this->typoScriptSetup = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
75  }
76 
87  public function render($typoscriptObjectPath, $data = null, $currentValueKey = null, $table = '')
88  {
89  if (TYPO3_MODE === 'BE') {
91  }
92  if ($data === null) {
93  $data = $this->renderChildren();
94  }
95  $currentValue = null;
96  if (is_object($data)) {
98  } elseif (is_string($data) || is_numeric($data)) {
99  $currentValue = (string)$data;
100  $data = [$data];
101  }
103  $contentObject = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
104  $contentObject->start($data, $table);
105  if ($currentValue !== null) {
106  $contentObject->setCurrentVal($currentValue);
107  } elseif ($currentValueKey !== null && isset($data[$currentValueKey])) {
108  $contentObject->setCurrentVal($data[$currentValueKey]);
109  }
110  $pathSegments = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('.', $typoscriptObjectPath);
111  $lastSegment = array_pop($pathSegments);
112  $setup = $this->typoScriptSetup;
113  foreach ($pathSegments as $segment) {
114  if (!array_key_exists(($segment . '.'), $setup)) {
115  throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('TypoScript object path "' . htmlspecialchars($typoscriptObjectPath) . '" does not exist', 1253191023);
116  }
117  $setup = $setup[$segment . '.'];
118  }
119  $content = $contentObject->cObjGetSingle($setup[$lastSegment], $setup[$lastSegment . '.']);
120  if (TYPO3_MODE === 'BE') {
121  $this->resetFrontendEnvironment();
122  }
123  return $content;
124  }
125 
132  protected function simulateFrontendEnvironment()
133  {
134  $this->tsfeBackup = isset($GLOBALS['TSFE']) ? $GLOBALS['TSFE'] : null;
135  $GLOBALS['TSFE'] = new \stdClass();
136  $GLOBALS['TSFE']->cObjectDepthCounter = 100;
137  }
138 
145  protected function resetFrontendEnvironment()
146  {
147  $GLOBALS['TSFE'] = $this->tsfeBackup;
148  }
149 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)