[TASK] Convert remaining ViewHelpers to static calling 84/52784/9
authorClaus Due <claus@namelesscoder.net>
Thu, 11 May 2017 18:59:40 +0000 (20:59 +0200)
committerBenni Mack <benni@typo3.org>
Mon, 12 Jun 2017 19:14:47 +0000 (21:14 +0200)
Last pass, touches all remaining ViewHelpers which
are capable of conversion to the compilation helper
traits from Fluid.

Change-Id: I73e32da48b00444b66a568f462ab41ff66969503
Resolves: #81200
Releases: master, 8.7
Reviewed-on: https://review.typo3.org/52784
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
13 files changed:
typo3/sysext/core/Classes/ViewHelpers/IconForRecordViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Be/PageRendererViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Be/Widget/PaginateViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/CObjectViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Form/ValidationResultsViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Format/CaseViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/RenderChildrenViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Widget/UriViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/CObjectViewHelperTest.php
typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Link/ClickEnlargeViewHelper.php
typo3/sysext/indexed_search/Classes/ViewHelpers/Format/DateTimeViewHelper.php
typo3/sysext/install/Classes/ViewHelpers/File/RelativePathViewHelper.php
typo3/sysext/install/Classes/ViewHelpers/PhpInfoViewHelper.php

index 47f5e1f..8f15a5d 100644 (file)
@@ -18,12 +18,16 @@ use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
 
 /**
  * Displays icon for record
  */
 class IconForRecordViewHelper extends AbstractViewHelper
 {
+    use CompileWithRenderStatic;
+
     /**
      * View helper returns HTML, thus we need to disable output escaping
      *
@@ -43,16 +47,17 @@ class IconForRecordViewHelper extends AbstractViewHelper
     }
 
     /**
-     * Prints icon html for record icon
-     *
+     * @param array $arguments
+     * @param \Closure $renderChildrenClosure
+     * @param RenderingContextInterface $renderingContext
      * @return string
      */
-    public function render() : string
+    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
     {
-        $table = $this->arguments['table'];
-        $size = $this->arguments['size'];
-        $row = $this->arguments['row'];
-        $alternativeMarkupIdentifier = $this->arguments['alternativeMarkupIdentifier'];
+        $table = $arguments['table'];
+        $size = $arguments['size'];
+        $row = $arguments['row'];
+        $alternativeMarkupIdentifier = $arguments['alternativeMarkupIdentifier'];
         /** @var IconFactory $iconFactory */
         $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
         return $iconFactory->getIconForRecord($table, $row, $size)->render($alternativeMarkupIdentifier);
index eb60cc0..5651c52 100644 (file)
@@ -15,8 +15,11 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Be;
  */
 
 use TYPO3\CMS\Core\Page\PageRenderer;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
 
 /**
  * View helper which allows you to create extbase based modules in the style of TYPO3 default modules.
@@ -35,18 +38,7 @@ use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
  */
 class PageRendererViewHelper extends AbstractViewHelper
 {
-    /**
-     * @var PageRenderer
-     */
-    protected $pageRenderer;
-
-    /**
-     * @param PageRenderer $pageRenderer
-     */
-    public function injectPageRenderer(PageRenderer $pageRenderer)
-    {
-        $this->pageRenderer = $pageRenderer;
-    }
+    use CompileWithRenderStatic;
 
     /**
      * Initialize arguments.
@@ -65,48 +57,60 @@ class PageRendererViewHelper extends AbstractViewHelper
     }
 
     /**
-     * Render start page with \TYPO3\CMS\Backend\Template\DocumentTemplate and pageTitle
+     * @param array $arguments
+     * @param \Closure $renderChildrenClosure
+     * @param RenderingContextInterface $renderingContext
      */
-    public function render()
+    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
     {
-        $pageTitle = $this->arguments['pageTitle'];
-        $includeCssFiles = $this->arguments['includeCssFiles'];
-        $includeJsFiles = $this->arguments['includeJsFiles'];
-        $addJsInlineLabels = $this->arguments['addJsInlineLabels'];
-        $includeRequireJsModules = $this->arguments['includeRequireJsModules'];
-        $addInlineSettings = $this->arguments['addInlineSettings'];
+        $pageRenderer = static::getPageRenderer();
+        $pageTitle = $arguments['pageTitle'];
+        $includeCssFiles = $arguments['includeCssFiles'];
+        $includeJsFiles = $arguments['includeJsFiles'];
+        $addJsInlineLabels = $arguments['addJsInlineLabels'];
+        $includeRequireJsModules = $arguments['includeRequireJsModules'];
+        $addInlineSettings = $arguments['addInlineSettings'];
 
         if ($pageTitle) {
-            $this->pageRenderer->setTitle($pageTitle);
+            $pageRenderer->setTitle($pageTitle);
         }
+
         // Include custom CSS and JS files
         if (is_array($includeCssFiles) && count($includeCssFiles) > 0) {
             foreach ($includeCssFiles as $addCssFile) {
-                $this->pageRenderer->addCssFile($addCssFile);
+                $pageRenderer->addCssFile($addCssFile);
             }
         }
         if (is_array($includeJsFiles) && count($includeJsFiles) > 0) {
             foreach ($includeJsFiles as $addJsFile) {
-                $this->pageRenderer->addJsFile($addJsFile);
+                $pageRenderer->addJsFile($addJsFile);
             }
         }
         if (is_array($includeRequireJsModules) && count($includeRequireJsModules) > 0) {
             foreach ($includeRequireJsModules as $addRequireJsFile) {
-                $this->pageRenderer->loadRequireJsModule($addRequireJsFile);
+                $pageRenderer->loadRequireJsModule($addRequireJsFile);
             }
         }
 
         if (is_array($addInlineSettings) && count($addInlineSettings) > 0) {
-            $this->pageRenderer->addInlineSettingArray(null, $addInlineSettings);
+            $pageRenderer->addInlineSettingArray(null, $addInlineSettings);
         }
 
         // Add inline language labels
         if (is_array($addJsInlineLabels) && count($addJsInlineLabels) > 0) {
-            $extensionKey = $this->controllerContext->getRequest()->getControllerExtensionKey();
+            $extensionKey = $renderingContext->getControllerContext()->getRequest()->getControllerExtensionKey();
             foreach ($addJsInlineLabels as $key) {
                 $label = LocalizationUtility::translate($key, $extensionKey);
-                $this->pageRenderer->addInlineLanguageLabel($key, $label);
+                $pageRenderer->addInlineLanguageLabel($key, $label);
             }
         }
     }
+
+    /**
+     * @return PageRenderer
+     */
+    protected static function getPageRenderer()
+    {
+        return GeneralUtility::makeInstance(PageRenderer::class);
+    }
 }
index 1545733..367c814 100644 (file)
@@ -13,6 +13,9 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Be\Widget;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
+use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Exception;
 
 /**
  * This ViewHelper renders a Pagination of objects for the TYPO3 Backend.
@@ -61,13 +64,27 @@ class PaginateViewHelper extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetView
     }
 
     /**
-     * @param \TYPO3\CMS\Extbase\Persistence\QueryResultInterface $objects
-     * @param string $as
-     * @param array $configuration
+     * Initialize arguments.
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('objects', 'mixed', 'Object', true);
+        $this->registerArgument('as', 'string', 'as', true);
+        $this->registerArgument('configuration', 'array', 'configuration', false, ['itemsPerPage' => 10, 'insertAbove' => false, 'insertBelow' => true, 'maximumNumberOfLinks' => 99]);
+    }
+
+    /**
+     * @throws Exception
      * @return string
      */
-    public function render(\TYPO3\CMS\Extbase\Persistence\QueryResultInterface $objects, $as, array $configuration = ['itemsPerPage' => 10, 'insertAbove' => false, 'insertBelow' => true, 'recordsLabel' => ''])
+    public function render()
     {
+        $objects = $this->arguments['objects'];
+
+        if (!($objects instanceof QueryResultInterface || $objects instanceof ObjectStorage || is_array($objects))) {
+            throw new Exception('Supplied file object type ' . get_class($objects) . ' must be QueryResultInterface or ObjectStorage or be an array.', 1454510732);
+        }
         return $this->initiateSubRequest();
     }
 }
index dc26420..562382c 100644 (file)
@@ -15,7 +15,11 @@ namespace TYPO3\CMS\Fluid\ViewHelpers;
  */
 
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
+use TYPO3\CMS\Extbase\Object\ObjectManager;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
+use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;
 
 /**
  * This ViewHelper renders CObjects from the global TypoScript configuration.
@@ -46,6 +50,8 @@ use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
  */
 class CObjectViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
 {
+    use CompileWithContentArgumentAndRenderStatic;
+
     /**
      * Disable escaping of child nodes' output
      *
@@ -61,41 +67,9 @@ class CObjectViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHel
     protected $escapeOutput = false;
 
     /**
-     * @var array
-     */
-    protected $typoScriptSetup;
-
-    /**
      * @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController contains a backup of the current $GLOBALS['TSFE'] if used in BE mode
      */
-    protected $tsfeBackup;
-
-    /**
-     * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
-     */
-    protected $configurationManager;
-
-    /**
-     * @var ContentObjectRenderer
-     */
-    protected $contentObjectRenderer;
-
-    /**
-     * @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
-     */
-    public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
-    {
-        $this->configurationManager = $configurationManager;
-        $this->typoScriptSetup = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
-    }
-
-    /**
-     * @param ContentObjectRenderer $contentObjectRenderer
-     */
-    public function injectContentObjectRenderer(ContentObjectRenderer $contentObjectRenderer)
-    {
-        $this->contentObjectRenderer = $contentObjectRenderer;
-    }
+    protected static $tsfeBackup;
 
     /**
      * Initialize arguments.
@@ -105,8 +79,8 @@ class CObjectViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHel
     public function initializeArguments()
     {
         parent::initializeArguments();
-        $this->registerArgument('typoscriptObjectPath', 'string', 'the TypoScript setup path of the TypoScript object to render', true);
         $this->registerArgument('data', 'mixed', 'the data to be used for rendering the cObject. Can be an object, array or string. If this argument is not set, child nodes will be used');
+        $this->registerArgument('typoscriptObjectPath', 'string', 'the TypoScript setup path of the TypoScript object to render', true);
         $this->registerArgument('currentValueKey', 'string', 'currentValueKey');
         $this->registerArgument('table', 'string', 'table', false, '');
     }
@@ -114,20 +88,21 @@ class CObjectViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHel
     /**
      * Renders the TypoScript object in the given TypoScript setup path.
      *
+     * @param array $arguments
+     * @param \Closure $renderChildrenClosure
+     * @param RenderingContextInterface $renderingContext
+     * @return mixed
      * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
-     * @return string the content of the rendered TypoScript object
      */
-    public function render()
+    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
     {
-        $typoscriptObjectPath = $this->arguments['typoscriptObjectPath'];
-        $data = $this->arguments['data'];
-        $currentValueKey = $this->arguments['currentValueKey'];
-        $table = $this->arguments['table'];
+        $data = $renderChildrenClosure();
+        $typoscriptObjectPath = $arguments['typoscriptObjectPath'];
+        $currentValueKey = $arguments['currentValueKey'];
+        $table = $arguments['table'];
+        $contentObjectRenderer = static::getContentObjectRenderer();
         if (TYPO3_MODE === 'BE') {
-            $this->simulateFrontendEnvironment();
-        }
-        if ($data === null) {
-            $data = $this->renderChildren();
+            static::simulateFrontendEnvironment();
         }
         $currentValue = null;
         if (is_object($data)) {
@@ -136,36 +111,53 @@ class CObjectViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHel
             $currentValue = (string)$data;
             $data = [$data];
         }
-        $this->contentObjectRenderer->start($data, $table);
+        $contentObjectRenderer->start($data, $table);
         if ($currentValue !== null) {
-            $this->contentObjectRenderer->setCurrentVal($currentValue);
+            $contentObjectRenderer->setCurrentVal($currentValue);
         } elseif ($currentValueKey !== null && isset($data[$currentValueKey])) {
-            $this->contentObjectRenderer->setCurrentVal($data[$currentValueKey]);
+            $contentObjectRenderer->setCurrentVal($data[$currentValueKey]);
         }
         $pathSegments = GeneralUtility::trimExplode('.', $typoscriptObjectPath);
         $lastSegment = array_pop($pathSegments);
-        $setup = $this->typoScriptSetup;
+        $setup = static::getConfigurationManager()->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
         foreach ($pathSegments as $segment) {
             if (!array_key_exists(($segment . '.'), $setup)) {
                 throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('TypoScript object path "' . htmlspecialchars($typoscriptObjectPath) . '" does not exist', 1253191023);
             }
             $setup = $setup[$segment . '.'];
         }
-        $content = $this->contentObjectRenderer->cObjGetSingle($setup[$lastSegment], $setup[$lastSegment . '.']);
+        $content = $contentObjectRenderer->cObjGetSingle($setup[$lastSegment], $setup[$lastSegment . '.']);
         if (TYPO3_MODE === 'BE') {
-            $this->resetFrontendEnvironment();
+            static::resetFrontendEnvironment();
         }
         return $content;
     }
 
     /**
+     * @return ConfigurationManagerInterface
+     */
+    protected static function getConfigurationManager()
+    {
+        return GeneralUtility::makeInstance(ObjectManager::class)->get(ConfigurationManagerInterface::class);
+    }
+
+    /**
+     * @return ContentObjectRenderer
+     */
+    protected static function getContentObjectRenderer()
+    {
+        return $GLOBALS['TSFE']->cObj;
+    }
+
+    /**
      * 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 function simulateFrontendEnvironment()
+    protected static function simulateFrontendEnvironment()
     {
-        $this->tsfeBackup = isset($GLOBALS['TSFE']) ? $GLOBALS['TSFE'] : null;
+        static::$tsfeBackup = isset($GLOBALS['TSFE']) ? $GLOBALS['TSFE'] : null;
         $GLOBALS['TSFE'] = new \stdClass();
+        $GLOBALS['TSFE']->cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
         $GLOBALS['TSFE']->cObjectDepthCounter = 100;
     }
 
@@ -174,8 +166,8 @@ class CObjectViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHel
      *
      * @see simulateFrontendEnvironment()
      */
-    protected function resetFrontendEnvironment()
+    protected static function resetFrontendEnvironment()
     {
-        $GLOBALS['TSFE'] = $this->tsfeBackup;
+        $GLOBALS['TSFE'] = static::$tsfeBackup;
     }
 }
index dda72da..572f2a0 100644 (file)
@@ -13,6 +13,8 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Form;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
 
 /**
  * Validation results view helper
@@ -63,6 +65,8 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Form;
  */
 class ValidationResultsViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
 {
+    use CompileWithRenderStatic;
+
     /**
      * As this ViewHelper renders HTML, the output must not be escaped.
      *
@@ -83,23 +87,25 @@ class ValidationResultsViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\Abstr
     }
 
     /**
-     * Iterates through selected errors of the request.
-     *
-     * @return string Rendered string
-     * @api
+     * @param array $arguments
+     * @param \Closure $renderChildrenClosure
+     * @param RenderingContextInterface $renderingContext
+     * @return mixed
      */
-    public function render()
+    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
     {
-        $for = $this->arguments['for'];
-        $as = $this->arguments['as'];
+        $templateVariableContainer = $renderingContext->getVariableProvider();
+        $controllerContext = $renderingContext->getcontrollerContext();
+        $for = $arguments['for'];
+        $as = $arguments['as'];
 
-        $validationResults = $this->controllerContext->getRequest()->getOriginalRequestMappingResults();
+        $validationResults = $controllerContext->getRequest()->getOriginalRequestMappingResults();
         if ($validationResults !== null && $for !== '') {
             $validationResults = $validationResults->forProperty($for);
         }
-        $this->templateVariableContainer->add($as, $validationResults);
-        $output = $this->renderChildren();
-        $this->templateVariableContainer->remove($as);
+        $templateVariableContainer->add($as, $validationResults);
+        $output = $renderChildrenClosure();
+        $templateVariableContainer->remove($as);
         return $output;
     }
 }
index 7fdecc9..d46f388 100644 (file)
@@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
 use TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException;
 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
 
 /**
  * Modifies the case of an input string to upper- or lowercase or capitalization.
@@ -66,6 +67,8 @@ use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
  */
 class CaseViewHelper extends AbstractViewHelper
 {
+    use CompileWithRenderStatic;
+
     /**
      * Directs the input string being converted to "lowercase"
      */
@@ -110,24 +113,6 @@ class CaseViewHelper extends AbstractViewHelper
     /**
      * Changes the case of the input string
      *
-     * @return string the altered string.
-     * @api
-     */
-    public function render()
-    {
-        return static::renderStatic(
-            [
-                'value' => $this->arguments['value'],
-                'mode' => $this->arguments['mode']
-            ],
-            $this->buildRenderChildrenClosure(),
-            $this->renderingContext
-        );
-    }
-
-    /**
-     * Changes the case of the input string
-     *
      * @param array $arguments
      * @param \Closure $renderChildrenClosure
      * @param RenderingContextInterface $renderingContext
index 61451c1..7e81866 100644 (file)
@@ -13,6 +13,8 @@ namespace TYPO3\CMS\Fluid\ViewHelpers;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
 
 /**
  * Render the inner parts of a Widget.
@@ -25,6 +27,8 @@ namespace TYPO3\CMS\Fluid\ViewHelpers;
  */
 class RenderChildrenViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
 {
+    use CompileWithRenderStatic;
+
     /**
      * As this ViewHelper might render HTML, the output must not be escaped
      *
@@ -42,48 +46,54 @@ class RenderChildrenViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\Abstract
     }
 
     /**
-     * @return string
+     * @param array $arguments
+     * @param \Closure $renderChildrenClosure
+     * @param RenderingContextInterface $renderingContext
+     * @return mixed
      */
-    public function render()
+    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
     {
-        $renderingContext = $this->getWidgetRenderingContext();
-        $widgetChildNodes = $this->getWidgetChildNodes();
-        $this->addArgumentsToTemplateVariableContainer($this->arguments['arguments']);
-        $output = $widgetChildNodes->evaluate($renderingContext);
-        $this->removeArgumentsFromTemplateVariableContainer($this->arguments['arguments']);
+        $subRenderingContext = static::getWidgetRenderingContext($renderingContext);
+        $widgetChildNodes = static::getWidgetChildNodes($renderingContext);
+        static::addArgumentsToTemplateVariableContainer($subRenderingContext, $arguments['arguments']);
+        $output = $widgetChildNodes->evaluate($subRenderingContext);
+        static::removeArgumentsFromTemplateVariableContainer($subRenderingContext, $arguments['arguments']);
         return $output;
     }
 
     /**
      * Get the widget rendering context, or throw an exception if it cannot be found.
      *
+     * @param RenderingContextInterface $renderingContext
      * @throws \TYPO3\CMS\Fluid\Core\Widget\Exception\RenderingContextNotFoundException
      * @return \TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface
      */
-    protected function getWidgetRenderingContext()
+    protected static function getWidgetRenderingContext(RenderingContextInterface $renderingContext)
     {
-        $renderingContext = $this->getWidgetContext()->getViewHelperChildNodeRenderingContext();
-        if (!$renderingContext instanceof \TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface) {
+        $subRenderingContext = static::getWidgetContext($renderingContext)->getViewHelperChildNodeRenderingContext();
+        if (!$subRenderingContext instanceof \TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface) {
             throw new \TYPO3\CMS\Fluid\Core\Widget\Exception\RenderingContextNotFoundException('Rendering Context not found inside Widget. <f:renderChildren> has been used in an AJAX Request, but is only usable in non-ajax mode.', 1284986604);
         }
-        return $renderingContext;
+        return $subRenderingContext;
     }
 
     /**
+     * @param RenderingContextInterface $renderingContext
      * @return \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode
      */
-    protected function getWidgetChildNodes()
+    protected static function getWidgetChildNodes(RenderingContextInterface $renderingContext)
     {
-        return $this->getWidgetContext()->getViewHelperChildNodes();
+        return static::getWidgetContext($renderingContext)->getViewHelperChildNodes();
     }
 
     /**
+     * @param RenderingContextInterface $renderingContext
      * @throws \TYPO3\CMS\Fluid\Core\Widget\Exception\WidgetRequestNotFoundException
      * @return \TYPO3\CMS\Fluid\Core\Widget\WidgetContext
      */
-    protected function getWidgetContext()
+    protected static function getWidgetContext(RenderingContextInterface $renderingContext)
     {
-        $request = $this->controllerContext->getRequest();
+        $request = $renderingContext->getControllerContext()->getRequest();
         if (!$request instanceof \TYPO3\CMS\Fluid\Core\Widget\WidgetRequest) {
             throw new \TYPO3\CMS\Fluid\Core\Widget\Exception\WidgetRequestNotFoundException('The Request is not a WidgetRequest! <f:renderChildren> must be called inside a Widget Template.', 1284986120);
         }
@@ -93,11 +103,12 @@ class RenderChildrenViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\Abstract
     /**
      * Add the given arguments to the TemplateVariableContainer of the widget.
      *
+     * @param RenderingContextInterface $renderingContext
      * @param array $arguments
      */
-    protected function addArgumentsToTemplateVariableContainer(array $arguments)
+    protected static function addArgumentsToTemplateVariableContainer(RenderingContextInterface $renderingContext, array $arguments)
     {
-        $templateVariableContainer = $this->getWidgetRenderingContext()->getVariableProvider();
+        $templateVariableContainer = $renderingContext->getVariableProvider();
         foreach ($arguments as $identifier => $value) {
             $templateVariableContainer->add($identifier, $value);
         }
@@ -106,11 +117,12 @@ class RenderChildrenViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\Abstract
     /**
      * Remove the given arguments from the TemplateVariableContainer of the widget.
      *
+     * @param RenderingContextInterface $renderingContext
      * @param array $arguments
      */
-    protected function removeArgumentsFromTemplateVariableContainer(array $arguments)
+    protected static function removeArgumentsFromTemplateVariableContainer(RenderingContextInterface $renderingContext, array $arguments)
     {
-        $templateVariableContainer = $this->getWidgetRenderingContext()->getVariableProvider();
+        $templateVariableContainer = $renderingContext->getVariableProvider();
         foreach ($arguments as $identifier => $value) {
             $templateVariableContainer->remove($identifier);
         }
index fe7b110..b1d4a31 100644 (file)
@@ -13,6 +13,8 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Widget;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
 
 /**
  * A view helper for creating URIs to extbase actions within widgets.
@@ -31,6 +33,8 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Widget;
  */
 class UriViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
 {
+    use CompileWithRenderStatic;
+
     /**
      * Initialize arguments
      *
@@ -48,38 +52,41 @@ class UriViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
     }
 
     /**
-     * Render the Uri.
-     *
-     * @return string The rendered link
-     * @api
+     * @param array $arguments
+     * @param \Closure $renderChildrenClosure
+     * @param RenderingContextInterface $renderingContext
+     * @return string
      */
-    public function render()
+    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
     {
-        $ajax = $this->arguments['ajax'];
+        $ajax = $arguments['ajax'];
 
         if ($ajax === true) {
-            return $this->getAjaxUri();
+            return static::getAjaxUri($renderingContext, $arguments);
         } else {
-            return $this->getWidgetUri();
+            return static::getWidgetUri($renderingContext, $arguments);
         }
     }
 
     /**
      * Get the URI for an AJAX Request.
      *
+     * @param RenderingContextInterface $renderingContext
+     * @param array $arguments
      * @return string the AJAX URI
      */
-    protected function getAjaxUri()
+    protected static function getAjaxUri(RenderingContextInterface $renderingContext, array $arguments)
     {
-        $action = $this->arguments['action'];
-        $arguments = $this->arguments['arguments'];
+        $controllerContext = $renderingContext->getControllerContext();
+        $action = $arguments['action'];
+        $arguments = $arguments['arguments'];
         if ($action === null) {
-            $action = $this->controllerContext->getRequest()->getControllerActionName();
+            $action = $controllerContext->getRequest()->getControllerActionName();
         }
         $arguments['id'] = $GLOBALS['TSFE']->id;
         // @todo page type should be configurable
         $arguments['type'] = 7076;
-        $arguments['fluid-widget-id'] = $this->controllerContext->getRequest()->getWidgetContext()->getAjaxWidgetIdentifier();
+        $arguments['fluid-widget-id'] = $controllerContext->getRequest()->getWidgetContext()->getAjaxWidgetIdentifier();
         $arguments['action'] = $action;
         return '?' . http_build_query($arguments, null, '&');
     }
@@ -87,26 +94,29 @@ class UriViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
     /**
      * Get the URI for a non-AJAX Request.
      *
+     * @param RenderingContextInterface $renderingContext
+     * @param array $arguments
      * @return string the Widget URI
      */
-    protected function getWidgetUri()
+    protected static function getWidgetUri(RenderingContextInterface $renderingContext, array $arguments)
     {
-        $uriBuilder = $this->controllerContext->getUriBuilder();
-        $argumentPrefix = $this->controllerContext->getRequest()->getArgumentPrefix();
-        $arguments = $this->hasArgument('arguments') ? $this->arguments['arguments'] : [];
-        if ($this->hasArgument('action')) {
-            $arguments['action'] = $this->arguments['action'];
+        $controllerContext = $renderingContext->getControllerContext();
+        $uriBuilder = $controllerContext->getUriBuilder();
+        $argumentPrefix = $controllerContext->getRequest()->getArgumentPrefix();
+        $parameters = $arguments['arguments'] ?? [];
+        if ($arguments['action'] ?? false) {
+            $parameters['action'] = $arguments['action'];
         }
-        if ($this->hasArgument('format') && $this->arguments['format'] !== '') {
-            $arguments['format'] = $this->arguments['format'];
+        if ($arguments['format'] ?? '' !== '') {
+            $parameters['format'] = $arguments['format'];
         }
         return $uriBuilder->reset()
-            ->setArguments([$argumentPrefix => $arguments])
-            ->setSection($this->arguments['section'])
+            ->setArguments([$argumentPrefix => $parameters])
+            ->setSection($arguments['section'])
             ->setAddQueryString(true)
-            ->setAddQueryStringMethod($this->arguments['addQueryStringMethod'])
+            ->setAddQueryStringMethod($arguments['addQueryStringMethod'])
             ->setArgumentsToBeExcludedFromQueryString([$argumentPrefix, 'cHash'])
-            ->setFormat($this->arguments['format'])
+            ->setFormat($arguments['format'])
             ->build();
     }
 }
index a156317..a877b45 100644 (file)
@@ -15,7 +15,9 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers;
  */
 
 use Prophecy\Argument;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
+use TYPO3\CMS\Extbase\Object\ObjectManager;
 use TYPO3\CMS\Fluid\ViewHelpers\CObjectViewHelper;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
@@ -137,12 +139,15 @@ class CObjectViewHelperTest extends ViewHelperBaseTestcase
         ];
 
         $this->configurationManager->getConfiguration(Argument::any())->willReturn($configArray);
-        $this->viewHelper->injectConfigurationManager($this->configurationManager->reveal());
 
         $this->contentObjectRenderer->start(['foo'], 'table')->willReturn();
         $this->contentObjectRenderer->setCurrentVal('foo')->willReturn();
         $this->contentObjectRenderer->cObjGetSingle('TEXT', $subConfigArray)->willReturn('Hello World');
-        $this->viewHelper->injectContentObjectRenderer($this->contentObjectRenderer->reveal());
+
+        $objectManager = $this->prophesize(ObjectManager::class);
+        $objectManager->get(ConfigurationManagerInterface::class)->willReturn($this->configurationManager->reveal());
+        GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager->reveal());
+        $GLOBALS['TSFE'] = (object) ['cObj' => $this->contentObjectRenderer->reveal()];
 
         $actualResult = $this->viewHelper->initializeArgumentsAndRender();
         $expectedResult = 'Hello World';
@@ -155,10 +160,11 @@ class CObjectViewHelperTest extends ViewHelperBaseTestcase
     protected function stubBaseDependencies()
     {
         $this->configurationManager->getConfiguration(Argument::any())->willReturn([]);
-        $this->viewHelper->injectConfigurationManager($this->configurationManager->reveal());
-
         $this->contentObjectRenderer->setCurrentVal(Argument::cetera())->willReturn();
         $this->contentObjectRenderer->cObjGetSingle(Argument::cetera())->willReturn('');
-        $this->viewHelper->injectContentObjectRenderer($this->contentObjectRenderer->reveal());
+        $objectManager = $this->prophesize(ObjectManager::class);
+        $objectManager->get(ConfigurationManagerInterface::class)->willReturn($this->configurationManager->reveal());
+        GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager->reveal());
+        $GLOBALS['TSFE'] = (object) ['cObj' => $this->contentObjectRenderer->reveal()];
     }
 }
index 2e4d062..4abaa6c 100644 (file)
@@ -21,6 +21,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
 
 /**
  * A view helper for creating a link for an image popup.
@@ -37,6 +38,8 @@ use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
  */
 class ClickEnlargeViewHelper extends AbstractViewHelper
 {
+    use CompileWithRenderStatic;
+
     /**
      * @var bool
      */
@@ -57,20 +60,6 @@ class ClickEnlargeViewHelper extends AbstractViewHelper
     }
 
     /**
-     * Render the view helper
-     *
-     * @return string
-     */
-    public function render()
-    {
-        return self::renderStatic(
-            $this->arguments,
-            $this->buildRenderChildrenClosure(),
-            $this->renderingContext
-        );
-    }
-
-    /**
      * @param array $arguments
      * @param \Closure $renderChildrenClosure
      * @param RenderingContextInterface $renderingContext
index 7e5f3df..cf3a66b 100644 (file)
@@ -17,12 +17,15 @@ namespace TYPO3\CMS\IndexedSearch\ViewHelpers\Format;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
 
 /**
  * DateTime viewhelper
  */
 class DateTimeViewHelper extends AbstractViewHelper
 {
+    use CompileWithRenderStatic;
+
     /**
      * The rendered children are fed into data() function, which expects an integer.
      * It reduces overhead and is safe to disable children escaping here.
@@ -34,18 +37,6 @@ class DateTimeViewHelper extends AbstractViewHelper
     /**
      * Render the given timestamp as date & time
      *
-     * @return string
-     */
-    public function render()
-    {
-        return static::renderStatic(
-            [],
-            $this->buildRenderChildrenClosure(),
-            $this->renderingContext
-        );
-    }
-
-    /**
      * @param array $arguments
      * @param \Closure $renderChildrenClosure
      * @param RenderingContextInterface $renderingContext
index cfe3cd9..5554fa6 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Install\ViewHelpers\File;
 
 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
 
 /**
  * Get file path relative to PATH_site from absolute path
@@ -33,6 +34,8 @@ use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
  */
 class RelativePathViewHelper extends AbstractViewHelper
 {
+    use CompileWithRenderStatic;
+
     /**
      * Output is escaped already. We must not escape children, to avoid double encoding.
      *
@@ -41,20 +44,6 @@ class RelativePathViewHelper extends AbstractViewHelper
     protected $escapeChildren = false;
 
     /**
-     * Get relative path
-     *
-     * @return string Relative path
-     */
-    public function render()
-    {
-        return static::renderStatic(
-            [],
-            $this->buildRenderChildrenClosure(),
-            $this->renderingContext
-        );
-    }
-
-    /**
      * @param array $arguments
      * @param \Closure $renderChildrenClosure
      * @param RenderingContextInterface $renderingContext
index f9b06f1..5d59dbf 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Install\ViewHelpers;
 
 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
 
 /**
  * Utility class for phpinfo()
@@ -23,6 +24,8 @@ use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
  */
 class PhpInfoViewHelper extends AbstractViewHelper
 {
+    use CompileWithRenderStatic;
+
     /**
      * @var bool
      */
@@ -34,20 +37,6 @@ class PhpInfoViewHelper extends AbstractViewHelper
     protected $escapeChildren = false;
 
     /**
-     * Render PHP info
-     *
-     * @return string
-     */
-    public function render()
-    {
-        return static::renderStatic(
-            [],
-            $this->buildRenderChildrenClosure(),
-            $this->renderingContext
-        );
-    }
-
-    /**
      * @param array $arguments
      * @param \Closure $renderChildrenClosure
      * @param RenderingContextInterface $renderingContext