[TASK] Makes InfoboxViewHelper compilable 76/39176/5
authorJan Helke <typo3@helke.de>
Fri, 1 May 2015 20:13:49 +0000 (22:13 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 2 May 2015 17:28:26 +0000 (19:28 +0200)
Resolves: #66723
Releases: master
Change-Id: I8a1a8c943e0e347df55d12712f5ec66684c56a77
Reviewed-on: http://review.typo3.org/39176
Reviewed-by: Frank Nägler <typo3@naegler.net>
Tested-by: Frank Nägler <typo3@naegler.net>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Controller/PageLayoutController.php
typo3/sysext/fluid/Classes/ViewHelpers/Be/InfoboxViewHelper.php
typo3/sysext/func/Classes/Controller/PageFunctionsController.php
typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateModuleController.php
typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateObjectBrowserModuleFunctionController.php

index 7344e2c..dbfecc8 100644 (file)
@@ -401,9 +401,15 @@ class PageLayoutController {
                                $message .= '<a class="btn btn-info" href="javascript:top.goToModule(\'web_list\',1);">' . $GLOBALS['LANG']->getLL('goToListModule') . '</a>';
                                // @todo Usage of InfoboxViewHelper this way is pretty ugly, but the best way at the moment
                                // A complete refactoring is necessary at this point
-                               $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
-                               $viewHelper = $objectManager->get(InfoboxViewHelper::class);
-                               $content .= $viewHelper->render($title, $message, InfoboxViewHelper::STATE_INFO);
+                               $arguments = array(
+                                       'title' => $title,
+                                       'message' => $message,
+                                       'state' => InfoboxViewHelper::STATE_INFO,
+                                       'iconName' => NULL,
+                                       'disableIcon' => FALSE,
+                               );
+                               $renderingContext = new \TYPO3\CMS\Fluid\Core\Rendering\RenderingContext();
+                               $content .= InfoboxViewHelper::renderStatic($arguments, function() {}, $renderingContext);
                        }
                }
                // If content from different pid is displayed
@@ -620,9 +626,16 @@ class PageLayoutController {
                        $message = $GLOBALS['LANG']->getLL('clickAPage_content');
                        // @todo Usage of InfoboxViewHelper this way is pretty ugly, but the best way at the moment
                        // A complete refactoring is necessary at this point
-                       $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
-                       $viewHelper = $objectManager->get(InfoboxViewHelper::class);
-                       $body .= $viewHelper->render($title, $message, InfoboxViewHelper::STATE_INFO);
+                       $arguments = array(
+                               'title' => $title,
+                               'message' => $message,
+                               'state' => InfoboxViewHelper::STATE_INFO,
+                               'iconName' => NULL,
+                               'disableIcon' => FALSE,
+                       );
+                       $renderingContext = new \TYPO3\CMS\Fluid\Core\Rendering\RenderingContext();
+                       $body .= InfoboxViewHelper::renderStatic($arguments, function() {}, $renderingContext);
+
                        // Setting up the buttons and markers for docheader
                        $docHeaderButtons = array(
                                'view' => '',
index 09dd423..bd9deec 100644 (file)
@@ -14,7 +14,9 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Be;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
 
 
 /**
@@ -47,7 +49,7 @@ use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
  *
  * @api
  */
-class InfoboxViewHelper extends AbstractViewHelper {
+class InfoboxViewHelper extends AbstractViewHelper implements CompilableInterface {
 
        const STATE_NOTICE = -2;
        const STATE_INFO = -1;
@@ -65,8 +67,36 @@ class InfoboxViewHelper extends AbstractViewHelper {
         * @return string
         */
        public function render($title = NULL, $message = NULL, $state = self::STATE_NOTICE, $iconName = NULL, $disableIcon = FALSE) {
+               return self::renderStatic(
+                       array(
+                               'title' => $title,
+                               'message' => $message,
+                               'state' => $state,
+                               'iconName' => $iconName,
+                               'disableIcon' => $disableIcon
+                       ),
+                       $this->buildRenderChildrenClosure(),
+                       $this->renderingContext
+               );
+       }
+
+       /**
+        * @param array $arguments
+        * @param callable $renderChildrenClosure
+        * @param RenderingContextInterface $renderingContext
+        *
+        * @return string
+        * @throws Exception
+        */
+       static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
+               $title = $arguments['title'];
+               $message = $arguments['message'];
+               $state = $arguments['state'];
+               $iconName = $arguments['iconName'];
+               $disableIcon = $arguments['disableIcon'];
+
                if ($message === NULL) {
-                       $message = $this->renderChildren();
+                       $message = $renderChildrenClosure();
                }
                switch ($state) {
                        case self::STATE_NOTICE:
@@ -105,14 +135,12 @@ class InfoboxViewHelper extends AbstractViewHelper {
                                                '<i class="fa fa-' . $icon . ' fa-stack-1x"></i>' .
                                        '</span>' .
                                '</div>';
-
                }
                $titleTemplate = '';
                if ($title !== NULL) {
                        $titleTemplate = '<h4 class="callout-title">' . $title . '</h4>';
                }
-               $template = '' .
-                       '<div class="callout callout-' . $stateClass . '">' .
+               return '<div class="callout callout-' . $stateClass . '">' .
                                '<div class="media">' .
                                        $iconTemplate .
                                        '<div class="media-body">' .
@@ -121,8 +149,5 @@ class InfoboxViewHelper extends AbstractViewHelper {
                                        '</div>' .
                                '</div>' .
                        '</div>';
-
-               return $template;
        }
-
 }
index 88c10a0..6b47e63 100644 (file)
@@ -104,9 +104,15 @@ class PageFunctionsController extends \TYPO3\CMS\Backend\Module\BaseScriptClass
                        $message = $this->getLanguageService()->getLL('clickAPage_content');
                        // @todo Usage of InfoboxViewHelper this way is pretty ugly, but the best way at the moment
                        // A complete refactoring is necessary at this point
-                       $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
-                       $viewHelper = $objectManager->get(InfoboxViewHelper::class);
-                       $this->content = $viewHelper->render($title, $message, InfoboxViewHelper::STATE_INFO);
+                       $arguments = array(
+                               'title' => $title,
+                               'message' => $message,
+                               'state' => InfoboxViewHelper::STATE_INFO,
+                               'iconName' => NULL,
+                               'disableIcon' => FALSE,
+                       );
+                       $renderingContext = new \TYPO3\CMS\Fluid\Core\Rendering\RenderingContext();
+                       $this->content = InfoboxViewHelper::renderStatic($arguments, function() {}, $renderingContext);
 
                        // Setting up the buttons and markers for docheader
                        $docHeaderButtons = $this->getButtons();
index 3393d1b..79a66bb 100644 (file)
@@ -360,9 +360,15 @@ class TypoScriptTemplateModuleController extends BaseScriptClass {
                $message = '<p>' . $lang->getLL('noTemplateDescription') . '<br />' . $lang->getLL('createTemplateToEditConfiguration') . '</p>';
                // @todo Usage of InfoboxViewHelper this way is pretty ugly, but the best way at the moment
                // A complete refactoring is necessary at this point
-               $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
-               $viewHelper = $objectManager->get(InfoboxViewHelper::class);
-               $theOutput = $viewHelper->render($title, $message, InfoboxViewHelper::STATE_INFO);
+               $arguments = array(
+                       'title' => $title,
+                       'message' => $message,
+                       'state' => InfoboxViewHelper::STATE_INFO,
+                       'iconName' => NULL,
+                       'disableIcon' => FALSE,
+               );
+               $renderingContext = new \TYPO3\CMS\Fluid\Core\Rendering\RenderingContext();
+               $theOutput = InfoboxViewHelper::renderStatic($arguments, function() {}, $renderingContext);
 
                // New standard?
                if ($newStandardTemplate) {
index ba81b90..ca27253 100644 (file)
@@ -440,9 +440,15 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFu
                                $message = '<p>' . implode($errMsg, '<br />') . '</p>';
                                // @todo Usage of InfoboxViewHelper this way is pretty ugly, but the best way at the moment
                                // A complete refactoring is necessary at this point
-                               $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
-                               $viewHelper = $objectManager->get(InfoboxViewHelper::class);
-                               $theOutput .= $viewHelper->render($title, $message, InfoboxViewHelper::STATE_WARNING);
+                               $arguments = array(
+                                       'title' => $title,
+                                       'message' => $message,
+                                       'state' => InfoboxViewHelper::STATE_WARNING,
+                                       'iconName' => NULL,
+                                       'disableIcon' => FALSE,
+                               );
+                               $renderingContext = new \TYPO3\CMS\Fluid\Core\Rendering\RenderingContext();
+                               $theOutput .= InfoboxViewHelper::renderStatic($arguments, function() {}, $renderingContext);
                        }
 
                        if (isset($this->pObj->MOD_SETTINGS['ts_browser_TLKeys_' . $bType][$theKey])) {