[TASK] Make JsonEncodeViewHelper compilable 03/40003/3
authorWouter Wolters <typo3@wouterwolters.nl>
Fri, 5 Jun 2015 18:11:33 +0000 (20:11 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Sat, 6 Jun 2015 13:27:27 +0000 (15:27 +0200)
Resolves: #67318
Releases: master
Change-Id: Ia5a32e24127bf0a3a6be5bf1c408991c5b2ba0f5
Reviewed-on: http://review.typo3.org/40003
Reviewed-by: Susanne Moog <typo3@susannemoog.de>
Tested-by: Susanne Moog <typo3@susannemoog.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/extensionmanager/Classes/ViewHelpers/Format/JsonEncodeViewHelper.php

index e8e4a14..e6deec6 100644 (file)
@@ -14,13 +14,17 @@ namespace TYPO3\CMS\Extensionmanager\ViewHelpers\Format;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
+
 /**
  * Wrapper for PHPs json_encode function.
  *
  * @see http://www.php.net/manual/en/function.json-encode.php
  * @internal
  */
-class JsonEncodeViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
+class JsonEncodeViewHelper extends AbstractViewHelper implements CompilableInterface {
 
        /**
         * Constructor
@@ -38,10 +42,26 @@ class JsonEncodeViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractView
         * @api
         */
        public function render() {
-               if ($this->hasArgument('additionalAttributes') && is_array($this->arguments['additionalAttributes'])) {
-                       return json_encode($this->arguments['additionalAttributes']);
+               return self::renderStatic(
+                       $this->arguments,
+                       $this->buildRenderChildrenClosure(),
+                       $this->renderingContext
+               );
+       }
+
+       /**
+        * @param array $arguments
+        * @param callable $renderChildrenClosure
+        * @param RenderingContextInterface $renderingContext
+        *
+        * @return string
+        */
+       static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
+               if (isset($arguments['additionalAttributes']) && is_array($arguments['additionalAttributes'])) {
+                       $content = $arguments['additionalAttributes'];
+               } else {
+                       $content = $renderChildrenClosure();
                }
-               $content = $this->renderChildren();
                return json_encode($content);
        }