[TASK] Make Uri/ResourceViewHelper compilable 00/39200/5
authordirk_juettner <dirk.juettner@gmail.com>
Sat, 2 May 2015 15:06:15 +0000 (17:06 +0200)
committerFrank Nägler <typo3@naegler.net>
Sat, 2 May 2015 17:09:56 +0000 (19:09 +0200)
Releases: master
Resolves: #66748
Change-Id: Id3ebb6bdc3da7d30c651ae178a363d8388d6ce63
Reviewed-on: http://review.typo3.org/39200
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
Reviewed-by: Frank Nägler <typo3@naegler.net>
Tested-by: Frank Nägler <typo3@naegler.net>
typo3/sysext/fluid/Classes/ViewHelpers/Uri/ResourceViewHelper.php

index ac53a94..187ef73 100644 (file)
@@ -13,6 +13,10 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Uri;
  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
  * Public License for more details.                                       *
  *                                                                        */
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
+
 /**
  * A view helper for creating URIs to resources.
  *
@@ -26,7 +30,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Uri;
  * (depending on current package)
  * </output>
  */
-class ResourceViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
+class ResourceViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper implements CompilableInterface {
 
        /**
         * Render the URI to the resource. The filename is used from child content.
@@ -38,17 +42,39 @@ class ResourceViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHe
         * @api
         */
        public function render($path, $extensionName = NULL, $absolute = FALSE) {
+               return self::renderStatic(
+                       array(
+                               'path' => $path,
+                               'extensionName' => $extensionName,
+                               'absolute' => $absolute
+                       ),
+                       $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) {
+               $path = $arguments['path'];
+               $extensionName = $arguments['extensionName'];
+               $absolute = $arguments['absolute'];
+
                if ($extensionName === NULL) {
-                       $extensionName = $this->controllerContext->getRequest()->getControllerExtensionName();
+                       $extensionName = $renderingContext->getControllerContext()->getRequest()->getControllerExtensionName();
                }
-               $uri = 'EXT:' . \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName) . '/Resources/Public/' . $path;
-               $uri = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($uri);
+               $uri = 'EXT:' . GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName) . '/Resources/Public/' . $path;
+               $uri = GeneralUtility::getFileAbsFileName($uri);
                $uri = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($uri);
                if (TYPO3_MODE === 'BE' && $absolute === FALSE && $uri !== FALSE) {
                        $uri = '../' . $uri;
                }
                if ($absolute === TRUE) {
-                       $uri = $this->controllerContext->getRequest()->getBaseURI() . $uri;
+                       $uri = $renderingContext->getControllerContext()->getRequest()->getBaseUri() . $uri;
                }
                return $uri;
        }