[TASK] Make \Be\Menus\ActionMenuItemViewHelper compilable 02/39202/7
authorMarkus Sommer <markussom@posteo.de>
Sat, 2 May 2015 15:52:29 +0000 (17:52 +0200)
committerAndreas Fernandez <typo3@scripting-base.de>
Sat, 2 May 2015 18:50:38 +0000 (20:50 +0200)
Implement CompilableInterface
getTagBuilder to get the TagBuilder for renderStatic function

Resolves: #66751
Releases: master
Change-Id: I57976c0b6c21bdc2be04f3e3224bcb28992f6611
Reviewed-on: http://review.typo3.org/39202
Reviewed-by: Frank Nägler <typo3@naegler.net>
Tested-by: Frank Nägler <typo3@naegler.net>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/fluid/Classes/Core/ViewHelper/AbstractTagBasedViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Be/Menus/ActionMenuItemViewHelper.php

index 5e80f6c..d08a2a2 100644 (file)
@@ -122,4 +122,13 @@ abstract class AbstractTagBasedViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelp
                $this->registerTagAttribute('onclick', 'string', 'JavaScript evaluated for the onclick event');
        }
 
+       /**
+        * Get the TagBuilder for renderStatic function
+        *
+        * @return TagBuilder
+        */
+       protected static function getTagBuilder(){
+               return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(TagBuilder::class);
+       }
+
 }
index b2e939a..bdecb57 100644 (file)
@@ -20,6 +20,11 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Be\Menus;
  *                                                                        *
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
+
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
+
 /**
  * View helper which returns a option tag.
  * This view helper only works in conjunction with \TYPO3\CMS\Fluid\ViewHelpers\Be\Menus\ActionMenuViewHelper
@@ -48,12 +53,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Be\Menus;
  * localized selectbox
  * <output>
  */
-class ActionMenuItemViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper {
-
-       /**
-        * @var string
-        */
-       protected $tagName = 'option';
+class ActionMenuItemViewHelper extends AbstractTagBasedViewHelper implements CompilableInterface {
 
        /**
         * Renders an ActionMenu option tag
@@ -61,22 +61,53 @@ class ActionMenuItemViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\Abstract
         * @param string $label label of the option tag
         * @param string $controller controller to be associated with this ActionMenuItem
         * @param string $action the action to be associated with this ActionMenuItem
-        * @param array $arguments additional controller arguments to be passed to the action when this ActionMenuItem is selected
+        * @param array $arguments additional controller arguments to be passed to the action when this ActionMenuItem is
+        *     selected
         * @return string the rendered option tag
         * @see \TYPO3\CMS\Fluid\ViewHelpers\Be\Menus\ActionMenuViewHelper
         */
        public function render($label, $controller, $action, array $arguments = array()) {
-               $uriBuilder = $this->controllerContext->getUriBuilder();
+               return self::renderStatic(
+                       array(
+                               'label' => $label,
+                               'controller' => $controller,
+                               'action' => $action,
+                               'arguments' => $arguments
+                       ),
+                       $this->buildRenderChildrenClosure(),
+                       $this->renderingContext
+               );
+       }
+
+       /**
+        * Render static for more speed in fluid
+        *
+        * @param array $arguments
+        * @param callable $renderChildrenClosure
+        * @param RenderingContextInterface $renderingContext
+        * @return string
+        */
+       static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
+               $label = $arguments['label'];
+               $controller = $arguments['controller'];
+               $action = $arguments['action'];
+               $arguments = $arguments['arguments'];
+
+               $tag = static::getTagBuilder();
+               $tag->setTagName('option');
+               $uriBuilder = $renderingContext->getControllerContext()->getUriBuilder();
                $uri = $uriBuilder->reset()->uriFor($action, $arguments, $controller);
-               $this->tag->addAttribute('value', $uri);
-               $currentRequest = $this->controllerContext->getRequest();
+
+               $tag->addAttribute('value', $uri);
+               $currentRequest = $renderingContext->getControllerContext()->getRequest();
                $currentController = $currentRequest->getControllerName();
                $currentAction = $currentRequest->getControllerActionName();
                if ($action === $currentAction && $controller === $currentController) {
-                       $this->tag->addAttribute('selected', 'selected');
+                       $tag->addAttribute('selected', 'selected');
                }
-               $this->tag->setContent($label);
-               return $this->tag->render();
+               $tag->setContent($label);
+               return $tag->render();
        }
 
+
 }