Skip to content
Snippets Groups Projects
Commit b26cf4e1 authored by Benni Mack's avatar Benni Mack
Browse files

[BUGFIX] Creating typolink in backend should not throw an exception

The global $TSFE object is not available in the Backend anymore.

In order to use <f:link.typolink> in e.g. a toolbar item or a preview
element, the TSFE object should be created as dummy so at least an index.php
URL (or external URL) is shown.

Resolves: #80669
Releases: master
Change-Id: I24a23a2d562c62e5663753bb80c75cc05164a6c9
Reviewed-on: https://review.typo3.org/52351


Reviewed-by: default avatarFrans Saris <franssaris@gmail.com>
Tested-by: default avatarFrans Saris <franssaris@gmail.com>
Reviewed-by: default avatarOliver Hader <oliver.hader@typo3.org>
Tested-by: default avatarOliver Hader <oliver.hader@typo3.org>
Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Tested-by: default avatarMona Muzaffar <mona.muzaffar@gmx.de>
Reviewed-by: default avatarBenni Mack <benni@typo3.org>
Tested-by: default avatarBenni Mack <benni@typo3.org>
parent 29f1d9f1
Branches
Tags
No related merge requests found
......@@ -16,10 +16,12 @@ namespace TYPO3\CMS\Frontend\Typolink;
*/
use TYPO3\CMS\Core\Service\DependencyOrderingService;
use TYPO3\CMS\Core\TypoScript\TemplateService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Frontend\Http\UrlProcessorInterface;
use TYPO3\CMS\Frontend\Page\PageRepository;
/**
* Abstract class to provide proper helper for most types necessary
......@@ -191,6 +193,22 @@ abstract class AbstractTypolinkBuilder
*/
public function getTypoScriptFrontendController(): TypoScriptFrontendController
{
if (!$GLOBALS['TSFE']) {
// This usually happens when typolink is created by the TYPO3 Backend, where no TSFE object
// is there. This functionality is currently completely internal, as these links cannot be
// created properly from the Backend.
// However, this is added to avoid any exceptions when trying to create a link
$GLOBALS['TSFE'] = GeneralUtility::makeInstance(
TypoScriptFrontendController::class,
[],
(int)GeneralUtility::_GP('id'),
(int)GeneralUtility::_GP('type')
);
$GLOBALS['TSFE']->sys_page = GeneralUtility::makeInstance(PageRepository::class);
$GLOBALS['TSFE']->sys_page->init(false);
$GLOBALS['TSFE']->tmpl = GeneralUtility::makeInstance(TemplateService::class);
$GLOBALS['TSFE']->tmpl->init();
}
return $GLOBALS['TSFE'];
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment