‪TYPO3CMS  11.5
EmailViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
21 
57 class ‪EmailViewHelper extends AbstractTagBasedViewHelper
58 {
62  protected ‪$tagName = 'a';
63 
67  public function ‪initializeArguments()
68  {
69  parent::initializeArguments();
70  $this->registerArgument('email', 'string', 'The email address to be turned into a link', true);
71  $this->registerUniversalTagAttributes();
72  $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
73  $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
74  $this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
75  $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
76  }
77 
81  public function ‪render()
82  {
83  $email = $this->arguments['email'];
84  $linkHref = 'mailto:' . $email;
85  $attributes = [];
86  $linkText = htmlspecialchars($email);
87  $escapeSpecialCharacters = true;
88  if (‪ApplicationType::fromRequest($this->renderingContext->getRequest())->isFrontend()) {
90  $frontend = ‪$GLOBALS['TSFE'];
91  // passing HTML encoded link text
92  $frontend->cObj->typoLink($linkText, ['parameter' => $linkHref]);
93  $linkResult = $frontend->cObj->lastTypoLinkResult;
94  if ($linkResult) {
95  $escapeSpecialCharacters = false;
96  $linkHref = $linkResult->getUrl();
97  $linkText = (string)$linkResult->getLinkText();
98  $attributes = $linkResult->getAttributes();
99  unset($attributes['href']);
100  }
101  }
102  $tagContent = $this->renderChildren();
103  if ($tagContent !== null) {
104  $linkText = $tagContent;
105  }
106  $this->tag->setContent($linkText);
107  $this->tag->addAttribute('href', $linkHref, $escapeSpecialCharacters);
108  $this->tag->forceClosingTag(true);
109  $this->tag->addAttributes($attributes, false);
110  return $this->tag->render();
111  }
112 }
‪TYPO3\CMS\Core\Http\ApplicationType\fromRequest
‪static static fromRequest(ServerRequestInterface $request)
Definition: ApplicationType.php:62
‪TYPO3\CMS\Core\Http\ApplicationType
Definition: ApplicationType.php:52
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:104
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25