[TASK] Don't simulate TSFE for CropViewHelper 42/49742/3
authorBenni Mack <benni@typo3.org>
Fri, 2 Sep 2016 09:02:50 +0000 (11:02 +0200)
committerJigal van Hemert <jigal.van.hemert@typo3.org>
Fri, 2 Sep 2016 19:36:34 +0000 (21:36 +0200)
The cObject cropping functionality was reworked quite a lot
and does not depend on TSFE anymore, so the code to simulate
TSFE object for backend requests can be removed.

Resolves: #77772
Releases: master
Change-Id: I7481e159658828be1672080590cbe98d2b3c5aa0
Reviewed-on: https://review.typo3.org/49742
Reviewed-by: Claus Due <claus@phpmind.net>
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
typo3/sysext/fluid/Classes/ViewHelpers/Format/CropViewHelper.php

index ac18809..19e8ac8 100644 (file)
@@ -15,7 +15,6 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  * The TYPO3 project - inspiring people to share!
  */
 
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Core\Charset\CharsetConverter;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
@@ -71,11 +70,6 @@ class CropViewHelper extends AbstractViewHelper
      */
     protected $escapeOutput = false;
 
      */
     protected $escapeOutput = false;
 
-    /**
-     * @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController contains a backup of the current['TSFE'] if used in BE mode
-     */
-    protected static $tsfeBackup;
-
     /**
      * Initialize arguments.
      *
     /**
      * Initialize arguments.
      *
@@ -131,9 +125,6 @@ class CropViewHelper extends AbstractViewHelper
         $respectHtml = $arguments['respectHtml'];
 
         $stringToTruncate = $renderChildrenClosure();
         $respectHtml = $arguments['respectHtml'];
 
         $stringToTruncate = $renderChildrenClosure();
-        if (TYPO3_MODE === 'BE') {
-            self::simulateFrontendEnvironment();
-        }
 
         // Even if we are in extbase/fluid context here, we're switching to a casual class of the framework here
         // that has no dependency injection and other stuff. Therefor it is ok to use makeInstance instead of
 
         // Even if we are in extbase/fluid context here, we're switching to a casual class of the framework here
         // that has no dependency injection and other stuff. Therefor it is ok to use makeInstance instead of
@@ -148,36 +139,7 @@ class CropViewHelper extends AbstractViewHelper
         } else {
             $content = $contentObject->crop($stringToTruncate, $maxCharacters . '|' . $append . '|' . $respectWordBoundaries);
         }
         } else {
             $content = $contentObject->crop($stringToTruncate, $maxCharacters . '|' . $append . '|' . $respectWordBoundaries);
         }
-        if (TYPO3_MODE === 'BE') {
-            self::resetFrontendEnvironment();
-        }
 
         return $content;
     }
 
         return $content;
     }
-
-    /**
-     * Sets the global variable $GLOBALS['TSFE']->csConvObj in Backend mode
-     * This somewhat hacky work around is currently needed because the crop() and cropHTML() functions of
-     * ContentObjectRenderer rely on those variables to be set.
-     * @throws \InvalidArgumentException
-     */
-    protected static function simulateFrontendEnvironment()
-    {
-        self::$tsfeBackup = isset($GLOBALS['TSFE']) ? $GLOBALS['TSFE'] : null;
-        $GLOBALS['TSFE'] = new \stdClass();
-        // preparing csConvObj
-        if (!is_object($GLOBALS['TSFE']->csConvObj)) {
-            $GLOBALS['TSFE']->csConvObj = GeneralUtility::makeInstance(CharsetConverter::class);
-        }
-    }
-
-    /**
-     * Resets $GLOBALS['TSFE'] if it was previously changed by simulateFrontendEnvironment().
-     *
-     * @see simulateFrontendEnvironment()
-     */
-    protected static function resetFrontendEnvironment()
-    {
-        $GLOBALS['TSFE'] = self::$tsfeBackup;
-    }
 }
 }