23 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
24 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
25 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;
82 use CompileWithContentArgumentAndRenderStatic;
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(
'typoscriptObjectPath',
'string',
'the TypoScript setup path of the TypoScript object to render',
true);
112 $this->registerArgument(
'currentValueKey',
'string',
'currentValueKey');
113 $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,
'');
125 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
127 $data = $renderChildrenClosure();
128 $typoscriptObjectPath = $arguments[
'typoscriptObjectPath'];
129 $currentValueKey = $arguments[
'currentValueKey'];
130 $table = $arguments[
'table'];
131 $contentObjectRenderer = static::getContentObjectRenderer();
133 static::simulateFrontendEnvironment();
135 $currentValue =
null;
136 if (is_object($data)) {
138 } elseif (is_string($data) || is_numeric($data)) {
139 $currentValue = (string)$data;
142 $contentObjectRenderer->start($data, $table);
143 if ($currentValue !==
null) {
144 $contentObjectRenderer->setCurrentVal($currentValue);
145 } elseif ($currentValueKey !==
null && isset($data[$currentValueKey])) {
146 $contentObjectRenderer->setCurrentVal($data[$currentValueKey]);
148 $pathSegments = GeneralUtility::trimExplode(
'.', $typoscriptObjectPath);
149 $lastSegment = array_pop($pathSegments);
151 foreach ($pathSegments as $segment) {
152 if (!array_key_exists($segment .
'.', $setup)) {
153 throw new \TYPO3Fluid\Fluid\Core\ViewHelper\Exception(
154 'TypoScript object path "' . $typoscriptObjectPath .
'" does not exist',
158 $setup = $setup[$segment .
'.'];
160 if (!isset($setup[$lastSegment])) {
161 throw new \TYPO3Fluid\Fluid\Core\ViewHelper\Exception(
162 'No Content Object definition found at TypoScript object path "' . $typoscriptObjectPath .
'"',
167 if (!isset(
$GLOBALS[
'TSFE']) || !(
$GLOBALS[
'TSFE'] instanceof TypoScriptFrontendController)) {
168 static::resetFrontendEnvironment();
182 protected static function renderContentObject(ContentObjectRenderer $contentObjectRenderer, array $setup,
string $typoscriptObjectPath,
string $lastSegment): string
184 $timeTracker = GeneralUtility::makeInstance(TimeTracker::class);
185 if ($timeTracker->LR) {
186 $timeTracker->push(
'/f:cObject/',
'<' . $typoscriptObjectPath);
188 $timeTracker->incStackPointer();
189 $content = $contentObjectRenderer->cObjGetSingle($setup[$lastSegment], $setup[$lastSegment .
'.'] ?? [], $typoscriptObjectPath);
190 $timeTracker->decStackPointer();
191 if ($timeTracker->LR) {
192 $timeTracker->pull($content);
202 return GeneralUtility::makeInstance(ObjectManager::class)->get(ConfigurationManagerInterface::class);
210 return GeneralUtility::makeInstance(
211 ContentObjectRenderer::class,
212 $GLOBALS[
'TSFE'] ?? GeneralUtility::makeInstance(TypoScriptFrontendController::class,
null, 0, 0)
222 static::$tsfeBackup =
$GLOBALS[
'TSFE'] ??
null;
224 $GLOBALS[
'TSFE']->cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
225 $GLOBALS[
'TSFE']->cObjectDepthCounter = 100;