TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
CObjectViewHelper.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
48 {
54  protected $escapeChildren = false;
55 
61  protected $escapeOutput = false;
62 
66  protected $typoScriptSetup;
67 
71  protected $tsfeBackup;
72 
77 
82 
87  public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
88  {
89  $this->configurationManager = $configurationManager;
90  $this->typoScriptSetup = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
91  }
92 
97  {
98  $this->contentObjectRenderer = $contentObjectRenderer;
99  }
100 
106  public function initializeArguments()
107  {
108  parent::initializeArguments();
109  $this->registerArgument('typoscriptObjectPath', 'string', 'the TypoScript setup path of the TypoScript object to render', true);
110  $this->registerArgument('data', 'mixed', 'the data to be used for rendering the cObject. Can be an object, array or string. If this argument is not set, child nodes will be used');
111  $this->registerArgument('currentValueKey', 'string', 'currentValueKey');
112  $this->registerArgument('table', 'string', 'table', false, '');
113  }
114 
121  public function render()
122  {
123  $typoscriptObjectPath = $this->arguments['typoscriptObjectPath'];
124  $data = $this->arguments['data'];
125  $currentValueKey = $this->arguments['currentValueKey'];
126  $table = $this->arguments['table'];
127  if (TYPO3_MODE === 'BE') {
129  }
130  if ($data === null) {
131  $data = $this->renderChildren();
132  }
133  $currentValue = null;
134  if (is_object($data)) {
136  } elseif (is_string($data) || is_numeric($data)) {
137  $currentValue = (string)$data;
138  $data = [$data];
139  }
140  $this->contentObjectRenderer->start($data, $table);
141  if ($currentValue !== null) {
142  $this->contentObjectRenderer->setCurrentVal($currentValue);
143  } elseif ($currentValueKey !== null && isset($data[$currentValueKey])) {
144  $this->contentObjectRenderer->setCurrentVal($data[$currentValueKey]);
145  }
146  $pathSegments = GeneralUtility::trimExplode('.', $typoscriptObjectPath);
147  $lastSegment = array_pop($pathSegments);
148  $setup = $this->typoScriptSetup;
149  foreach ($pathSegments as $segment) {
150  if (!array_key_exists(($segment . '.'), $setup)) {
151  throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('TypoScript object path "' . htmlspecialchars($typoscriptObjectPath) . '" does not exist', 1253191023);
152  }
153  $setup = $setup[$segment . '.'];
154  }
155  $content = $this->contentObjectRenderer->cObjGetSingle($setup[$lastSegment], $setup[$lastSegment . '.']);
156  if (TYPO3_MODE === 'BE') {
157  $this->resetFrontendEnvironment();
158  }
159  return $content;
160  }
161 
168  protected function simulateFrontendEnvironment()
169  {
170  $this->tsfeBackup = isset($GLOBALS['TSFE']) ? $GLOBALS['TSFE'] : null;
171  $GLOBALS['TSFE'] = new \stdClass();
172  $GLOBALS['TSFE']->cObjectDepthCounter = 100;
173  }
174 
181  protected function resetFrontendEnvironment()
182  {
183  $GLOBALS['TSFE'] = $this->tsfeBackup;
184  }
185 }
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']
injectContentObjectRenderer(ContentObjectRenderer $contentObjectRenderer)
injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)