[TASK] Make Url/EmailViewHelper compilable 65/39165/2
authorJan Helke <typo3@helke.de>
Fri, 1 May 2015 18:03:50 +0000 (20:03 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 2 May 2015 10:57:03 +0000 (12:57 +0200)
Resolves: #66715
Releases: master
Change-Id: Iac1648be8a6898077d42844003c194bb17f85f17
Reviewed-on: http://review.typo3.org/39165
Reviewed-by: Dirk Jüttner <dirk.juettner@gmail.com>
Tested-by: Dirk Jüttner <dirk.juettner@gmail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/fluid/Classes/ViewHelpers/Uri/EmailViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Uri/EmailViewHelperTest.php

index 74a4655..87e6544 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\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
+
 /**
  * Email URI view helper.
  * Generates an email URI incorporating TYPO3s spamProtectEmailAddresses-settings.
@@ -27,13 +31,32 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Uri;
  * (depending on your spamProtectEmailAddresses-settings)
  * </output>
  */
-class EmailViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
+class EmailViewHelper extends AbstractViewHelper implements CompilableInterface {
 
        /**
         * @param string $email The email address to be turned into a URI
         * @return string Rendered email link
         */
        public function render($email) {
+               return self::renderStatic(
+                       array(
+                               'email' => $email
+                       ),
+                       $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) {
+               $email = $arguments['email'];
+
                if (TYPO3_MODE === 'FE') {
                        $emailParts = $GLOBALS['TSFE']->cObj->getMailTo($email, $email);
                        return reset($emailParts);
@@ -41,5 +64,4 @@ class EmailViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelpe
                        return 'mailto:' . $email;
                }
        }
-
 }
index b0cc84c..58002e9 100644 (file)
@@ -20,11 +20,14 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Uri;
  *                                                                        *
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
+use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
+use TYPO3\CMS\Fluid\ViewHelpers\Uri\EmailViewHelper;
+use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
 
 /**
  * Testcase for the email uri view helper
  */
-class EmailViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase {
+class EmailViewHelperTest extends ViewHelperBaseTestcase {
 
        /**
         * @var \TYPO3\CMS\Fluid\ViewHelpers\Uri\EmailViewHelper
@@ -34,8 +37,8 @@ class EmailViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHe
        protected function setUp() {
                parent::setUp();
                $GLOBALS['TSFE'] = new \stdClass();
-               $GLOBALS['TSFE']->cObj = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, array(), array(), '', FALSE);
-               $this->viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\Uri\EmailViewHelper();
+               $GLOBALS['TSFE']->cObj = $this->getMock(ContentObjectRenderer::class, array(), array(), '', FALSE);
+               $this->viewHelper = new EmailViewHelper();
                $this->injectDependenciesIntoViewHelper($this->viewHelper);
                $this->viewHelper->initializeArguments();
        }