[BUGFIX] Creating typolink in backend should not throw an exception 51/52351/3
authorBenni Mack <benni@typo3.org>
Tue, 4 Apr 2017 06:38:15 +0000 (08:38 +0200)
committerBenni Mack <benni@typo3.org>
Tue, 4 Apr 2017 08:01:40 +0000 (10:01 +0200)
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: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/frontend/Classes/Typolink/AbstractTypolinkBuilder.php

index c82d0dd..3deae1b 100644 (file)
@@ -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'];
     }
 }