TYPO3 CMS  TYPO3_8-7
CObjectViewHelper.php
Go to the documentation of this file.
1 <?php
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 
86  public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
87  {
88  $this->configurationManager = $configurationManager;
89  $this->typoScriptSetup = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
90  }
91 
96  {
97  $this->contentObjectRenderer = $contentObjectRenderer;
98  }
99 
105  public function initializeArguments()
106  {
107  parent::initializeArguments();
108  $this->registerArgument('typoscriptObjectPath', 'string', 'the TypoScript setup path of the TypoScript object to render', true);
109  $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');
110  $this->registerArgument('currentValueKey', 'string', 'currentValueKey');
111  $this->registerArgument('table', 'string', 'the table name associated with "data" argument. Typically tt_content or one of your custom tables. This argument should be set if rendering a FILES cObject where file references are used, or if the data argument is a database record.', false, '');
112  }
113 
120  public function render()
121  {
122  $typoscriptObjectPath = $this->arguments['typoscriptObjectPath'];
123  $data = $this->arguments['data'];
124  $currentValueKey = $this->arguments['currentValueKey'];
125  $table = $this->arguments['table'];
126  if (TYPO3_MODE === 'BE') {
128  }
129  if ($data === null) {
130  $data = $this->renderChildren();
131  }
132  $currentValue = null;
133  if (is_object($data)) {
135  } elseif (is_string($data) || is_numeric($data)) {
136  $currentValue = (string)$data;
137  $data = [$data];
138  }
139  $this->contentObjectRenderer->start($data, $table);
140  if ($currentValue !== null) {
141  $this->contentObjectRenderer->setCurrentVal($currentValue);
142  } elseif ($currentValueKey !== null && isset($data[$currentValueKey])) {
143  $this->contentObjectRenderer->setCurrentVal($data[$currentValueKey]);
144  }
145  $pathSegments = GeneralUtility::trimExplode('.', $typoscriptObjectPath);
146  $lastSegment = array_pop($pathSegments);
147  $setup = $this->typoScriptSetup;
148  foreach ($pathSegments as $segment) {
149  if (!array_key_exists(($segment . '.'), $setup)) {
150  throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('TypoScript object path "' . htmlspecialchars($typoscriptObjectPath) . '" does not exist', 1253191023);
151  }
152  $setup = $setup[$segment . '.'];
153  }
154  $content = $this->contentObjectRenderer->cObjGetSingle($setup[$lastSegment], $setup[$lastSegment . '.']);
155  if (TYPO3_MODE === 'BE') {
156  $this->resetFrontendEnvironment();
157  }
158  return $content;
159  }
160 
165  protected function simulateFrontendEnvironment()
166  {
167  $this->tsfeBackup = isset($GLOBALS['TSFE']) ? $GLOBALS['TSFE'] : null;
168  $GLOBALS['TSFE'] = new \stdClass();
169  $GLOBALS['TSFE']->cObjectDepthCounter = 100;
170  }
171 
177  protected function resetFrontendEnvironment()
178  {
179  $GLOBALS['TSFE'] = $this->tsfeBackup;
180  }
181 }
injectContentObjectRenderer(ContentObjectRenderer $contentObjectRenderer)
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)