[TASK] Update php-cs-fixer to 2.5.0
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Uri / EmailViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Uri;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
17 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
18 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
19
20 /**
21 * Email URI view helper.
22 * Generates an email URI incorporating TYPO3s spamProtectEmailAddresses-settings.
23 *
24 * = Examples
25 *
26 * <code title="basic email URI">
27 * <f:uri.email email="foo@bar.tld" />
28 * </code>
29 * <output>
30 * javascript:linkTo_UnCryptMailto('ocknvq,hqqBdct0vnf');
31 * (depending on your spamProtectEmailAddresses-settings)
32 * </output>
33 */
34 class EmailViewHelper extends AbstractViewHelper
35 {
36 use CompileWithRenderStatic;
37
38 /**
39 * Initialize arguments
40 *
41 * @api
42 */
43 public function initializeArguments()
44 {
45 parent::initializeArguments();
46 $this->registerArgument('email', 'string', 'The email address to be turned into a URI', true);
47 }
48
49 /**
50 * @param array $arguments
51 * @param \Closure $renderChildrenClosure
52 * @param RenderingContextInterface $renderingContext
53 *
54 * @return string Rendered email link
55 */
56 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
57 {
58 $email = $arguments['email'];
59
60 if (TYPO3_MODE === 'FE') {
61 $emailParts = $GLOBALS['TSFE']->cObj->getMailTo($email, $email);
62 return reset($emailParts);
63 }
64 return 'mailto:' . $email;
65 }
66 }