[TASK] Fluid RenderViewHelper compilable 53/37453/4
authorChristian Kuhn <lolli@schwarzbu.ch>
Mon, 2 Mar 2015 11:24:05 +0000 (12:24 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Mon, 2 Mar 2015 16:06:49 +0000 (17:06 +0100)
Resolves: #65451
Releases: master
Change-Id: Ia08ec9b586a2b080763f07ee2fe6e257ca484397
Reviewed-on: http://review.typo3.org/37453
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Helmut Hummel <helmut.hummel@typo3.org>
Tested-by: Helmut Hummel <helmut.hummel@typo3.org>
typo3/sysext/fluid/Classes/ViewHelpers/RenderViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/RenderViewHelperTest.php

index 81e7ea0..51c004f 100644 (file)
@@ -11,6 +11,10 @@ namespace TYPO3\CMS\Fluid\ViewHelpers;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
+
 /**
  * ViewHelper that renders a section or a specified partial
  *
@@ -69,7 +73,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers;
  *
  * @api
  */
-class RenderViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
+class RenderViewHelper extends AbstractViewHelper implements CompilableInterface {
 
        /**
         * Renders the content.
@@ -82,13 +86,39 @@ class RenderViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelp
         * @api
         */
        public function render($section = NULL, $partial = NULL, $arguments = array(), $optional = FALSE) {
-               $arguments = $this->loadSettingsIntoArguments($arguments);
+               return self::renderStatic(
+                       array(
+                               'section' => $section,
+                               'partial' => $partial,
+                               'arguments' => $arguments,
+                               'optional' => $optional,
+                       ),
+                       $this->buildRenderChildrenClosure(),
+                       $this->renderingContext
+               );
+       }
+
+       /**
+        * Renders the content.
+        *
+        * @param array $arguments
+        * @param \Closure $renderChildrenClosure
+        * @param RenderingContextInterface $renderingContext
+        * @return string
+        */
+       static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
+               $section = $arguments['section'];
+               $partial = $arguments['partial'];
+               $optional = $arguments['optional'];
+               $arguments = static::loadSettingsIntoArguments($arguments['arguments'], $renderingContext);
 
+               $viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer();
                if ($partial !== NULL) {
-                       return $this->viewHelperVariableContainer->getView()->renderPartial($partial, $section, $arguments);
+                       return $viewHelperVariableContainer->getView()->renderPartial($partial, $section, $arguments);
                } elseif ($section !== NULL) {
-                       return $this->viewHelperVariableContainer->getView()->renderSection($section, $arguments, $optional);
+                       return $viewHelperVariableContainer->getView()->renderSection($section, $arguments, $optional);
                }
+
                return '';
        }
 
@@ -96,11 +126,13 @@ class RenderViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelp
         * If $arguments['settings'] is not set, it is loaded from the TemplateVariableContainer (if it is available there).
         *
         * @param array $arguments
+        * @param RenderingContextInterface $renderingContext
         * @return array
         */
-       protected function loadSettingsIntoArguments($arguments) {
-               if (!isset($arguments['settings']) && $this->templateVariableContainer->exists('settings')) {
-                       $arguments['settings'] = $this->templateVariableContainer->get('settings');
+       static protected function loadSettingsIntoArguments($arguments, RenderingContextInterface $renderingContext) {
+               $templateVariableContainer = $renderingContext->getTemplateVariableContainer();
+               if (!isset($arguments['settings']) && $templateVariableContainer->exists('settings')) {
+                       $arguments['settings'] = $templateVariableContainer->get('settings');
                }
                return $arguments;
        }
index 415c1da..7a7ae2d 100644 (file)
@@ -42,7 +42,7 @@ class RenderViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewH
                );
                $this->templateVariableContainer->add('settings', 'theSettings');
 
-               $actual = $this->viewHelper->_call('loadSettingsIntoArguments', $arguments);
+               $actual = $this->viewHelper->_call('loadSettingsIntoArguments', $arguments, $this->renderingContext);
                $this->assertEquals($expected, $actual);
        }
 
@@ -60,7 +60,7 @@ class RenderViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewH
                );
                $this->templateVariableContainer->add('settings', 'theSettings');
 
-               $actual = $this->viewHelper->_call('loadSettingsIntoArguments', $arguments);
+               $actual = $this->viewHelper->_call('loadSettingsIntoArguments', $arguments, $this->renderingContext);
                $this->assertEquals($expected, $actual);
        }
 
@@ -75,7 +75,7 @@ class RenderViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewH
                        'someArgument' => 'someValue'
                );
 
-               $actual = $this->viewHelper->_call('loadSettingsIntoArguments', $arguments);
+               $actual = $this->viewHelper->_call('loadSettingsIntoArguments', $arguments, $this->renderingContext);
                $this->assertEquals($expected, $actual);
        }