From 7d050ea075c760d4071564210900c2ab2fe9c870 Mon Sep 17 00:00:00 2001
From: Claus Due <claus@namelesscoder.net>
Date: Fri, 31 Jan 2020 21:01:57 +0100
Subject: [PATCH] [TASK] Add base Widget class methods for Fluid 3.0 compat

Adds two new methods, evaluate() and onClose() which
makes Widgets compatible with Fluid 3.0 but which are
never called on Fluid 2.x.

Releases: master, 9.5, 8.7
Resolves: #90286
Change-Id: I36a99c30e7c3bb5baae065cfc6368a2bf493cc40
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63133
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
---
 .../Core/Widget/AbstractWidgetViewHelper.php  | 34 +++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/typo3/sysext/fluid/Classes/Core/Widget/AbstractWidgetViewHelper.php b/typo3/sysext/fluid/Classes/Core/Widget/AbstractWidgetViewHelper.php
index 3c969cc5ce66..21574e5997f7 100644
--- a/typo3/sysext/fluid/Classes/Core/Widget/AbstractWidgetViewHelper.php
+++ b/typo3/sysext/fluid/Classes/Core/Widget/AbstractWidgetViewHelper.php
@@ -14,8 +14,10 @@ namespace TYPO3\CMS\Fluid\Core\Widget;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3Fluid\Fluid\Component\ComponentInterface;
 use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
 use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
+use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
 
 abstract class AbstractWidgetViewHelper extends AbstractViewHelper
@@ -124,6 +126,38 @@ abstract class AbstractWidgetViewHelper extends AbstractViewHelper
         return $this->callRenderMethod();
     }
 
+    /**
+     * Initialize the arguments of the ViewHelper, and call the render() method of the ViewHelper.
+     *
+     * @param RenderingContextInterface $renderingContext
+     * @return string the rendered ViewHelper.
+     * @internal
+     */
+    public function evaluate(RenderingContextInterface $renderingContext)
+    {
+        $this->renderingContext = $renderingContext;
+        $this->getArguments()->setRenderingContext($renderingContext);
+        $this->initializeWidgetContext();
+        return $this->callRenderMethod();
+    }
+
+    /**
+     * Stores the syntax tree child nodes in the Widget Context, so they can be
+     * rendered with <f:widget.renderChildren> lateron.
+     *
+     * @param RenderingContextInterface $renderingContext
+     * @return ComponentInterface
+     * @internal
+     */
+    public function onClose(RenderingContextInterface $renderingContext): ComponentInterface
+    {
+        $node = parent::onClose($renderingContext);
+        $rootNode = $this->objectManager->get(\TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\RootNode::class);
+        $rootNode->setChildren($this->getChildren());
+        $this->widgetContext->setViewHelperChildNodes($rootNode, $renderingContext);
+        return $node;
+    }
+
     /**
      * Initialize the Widget Context, before the Render method is called.
      */
-- 
GitLab