Ceremony
Ceremony

Reputation: 199

TYPO3 v10: How to access TSFE in Backend/Scheduler Task?

The current situation:
I am trying to access the TypoScript configuration of the frontend from within the backend (or rather a scheduler task). Previously with Typo3 v8 and v9, I initialized entire $GLOBALS["TSFE"] object, however this was already hack the last time around (using mostly deprecated calls) and now it has all been removed with the v10 release.

My goal:
Access the TypoScript configuration of the frontend of a certain page (root page of a site would be fine) from within a scheduler job.

Background of the whole project:
I have a periodic scheduler job that sends emails to various users (fe_users). The email contains links to certain pages (configured UIDs in typoscript) as well as file attachments and the likes (generated by other extensions, which are also fully configured via typoscript). Currently, I basically initialize the entire frontend from within the backend, but as I said before, its inefficient, super hacky and I doubt it was the intended way to solve this problem.

Upvotes: 2

Views: 1532

Answers (2)

Jonas Eberle
Jonas Eberle

Reputation: 2921

Getting TypoScript settings in the backend is ugly, but possible.

You need a page ID and a rootline which you can pass to \TYPO3\CMS\Core\TypoScript\TemplateService::runThroughTemplates().

Something along these lines:

$template = GeneralUtility::makeInstance(TemplateService::class);
$template->tt_track = false;
$rootline = GeneralUtility::makeInstance(
  RootlineUtility::class, $pageId
)->get();
$template->runThroughTemplates($rootline, 0);
$template->generateConfig();
$typoScriptSetup = $template->setup;

You can get inspiration from \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::getTypoScriptSetup and \TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateObjectBrowserModuleFunctionController

Upvotes: 3

Georg Ringer
Georg Ringer

Reputation: 7939

This won't get any better and is not intended to be done such way. I would use as configuration:

  • plain PHP, e.g. in $GLOBALS['TYPO3_CONF_VARS]`
  • YAML site config if depending on various sites

You can build links by using e.g. something like that

protected function generateUrl(int $pageId, int $recordId)
    {
        $additionalParams = 'tx_xxxx[action]=show&tx_ixxxx[controller]=Job&tx_xxxx[job]=' . $recordId;
        return BackendUtility::getPreviewUrl($pageId, '', null, '', '', $additionalParams);
    }

Upvotes: 2

Related Questions