diff --git a/Classes/Domain/Service/ParseNewsletterUrlService.php b/Classes/Domain/Service/ParseNewsletterUrlService.php index 43370624..f83f6bfb 100644 --- a/Classes/Domain/Service/ParseNewsletterUrlService.php +++ b/Classes/Domain/Service/ParseNewsletterUrlService.php @@ -19,6 +19,7 @@ use TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException; use TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException; use TYPO3\CMS\Fluid\View\StandaloneView; +use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; /** * Class ParseNewsletterUrlService to fill a container html with a content from a http(s) page. @@ -42,6 +43,13 @@ class ParseNewsletterUrlService */ protected $parseVariables = true; + /** + * Contains a backup of the current $GLOBALS['TSFE'] if used in BE mode + * + * @var TypoScriptFrontendController + */ + protected static $tsfeBackup; + /** * ParseNewsletterUrlService constructor. * @param string $origin can be a page uid or a complete url @@ -144,6 +152,9 @@ protected function getNewsletterContainerAndContent(string $content, User $user) */ protected function getContentObjectVariables(array $configuration): array { + if (TYPO3_MODE === 'BE') { + self::simulateFrontendEnvironment(); + } $tsService = ObjectUtility::getObjectManager()->get(TypoScriptService::class); $tsConfiguration = $tsService->convertPlainArrayToTypoScriptArray($configuration); @@ -161,6 +172,10 @@ protected function getContentObjectVariables(array $configuration): array ); } + if (TYPO3_MODE === 'BE') { + self::resetFrontendEnvironment(); + } + return $variables; } @@ -219,6 +234,31 @@ protected function getBodyFromHtml(string $string): string return $string; } + /** + * Sets the $TSFE->cObjectDepthCounter in Backend mode + * This somewhat hacky work around is currently needed because the cObjGetSingle() function of \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer relies on this setting + */ + protected static function simulateFrontendEnvironment() + { + if (!$GLOBALS['TSFE'] instanceof TypoScriptFrontendController) { + $GLOBALS['TSFE'] = new \stdClass(); + $GLOBALS['TSFE']->cObj = ObjectUtility::getContentObject(); + $GLOBALS['TSFE']->cObjectDepthCounter = 100; + } + } + + /** + * Resets $GLOBALS['TSFE'] if it was previously changed by simulateFrontendEnvironment() + * + * @see simulateFrontendEnvironment() + */ + protected static function resetFrontendEnvironment() + { + if (!$GLOBALS['TSFE'] instanceof TypoScriptFrontendController) { + $GLOBALS['TSFE'] = null; + } + } + /** * @return bool */