Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Simulate TSFE while processing variables #46

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Classes/Domain/Service/ParseNewsletterUrlService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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);

Expand All @@ -161,6 +172,10 @@ protected function getContentObjectVariables(array $configuration): array
);
}

if (TYPO3_MODE === 'BE') {
self::resetFrontendEnvironment();
}

return $variables;
}

Expand Down Expand Up @@ -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
*/
Expand Down