Commit 43944c34 authored by Benni Mack's avatar Benni Mack
Browse files

[BUGFIX] Use typolink in EmailViewHelper

This change uses typolink in EmailViewHelper,
allowing to also use typolink hooks or custom
Email Link Builder to be used consistently
across TYPO3 Core (e.g. using the same hooks
for all email link generation in the Frontend).

Resolves: #96483
Releases: main, 11.5
Change-Id: Ia573dc5a7ebb9ca7f0f0b6b35126bd789f86a627
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72924

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 9f562632
......@@ -81,15 +81,29 @@ class EmailViewHelper extends AbstractTagBasedViewHelper
public function render()
{
$email = $this->arguments['email'];
$linkHref = 'mailto:' . $email;
$attributes = [];
$linkText = htmlspecialchars($email);
$escapeSpecialCharacters = true;
if (ApplicationType::fromRequest($this->renderingContext->getRequest())->isFrontend()) {
/** @var TypoScriptFrontendController $frontend */
$frontend = $GLOBALS['TSFE'];
[$linkHref, $linkText, $attributes] = $frontend->cObj->getMailTo($email, '');
$escapeSpecialCharacters = !isset($frontend->spamProtectEmailAddresses) || $frontend->spamProtectEmailAddresses !== 'ascii';
} else {
$linkHref = 'mailto:' . $email;
$linkText = htmlspecialchars($email);
$escapeSpecialCharacters = true;
$frontend->cObj->typoLink($email, ['parameter' => $linkHref]);
$linkResult = $frontend->cObj->lastTypoLinkResult;
if ($linkResult) {
$escapeSpecialCharacters = false;
$linkHref = $linkResult->getUrl();
$linkText = (string)$linkResult->getLinkText();
$attributes = $linkResult->getAttributes();
unset($attributes['href']);
if ($frontend->spamProtectEmailAddresses !== 'ascii') {
if (PHP_VERSION_ID < 80100) {
$linkText = htmlspecialchars($linkText, ENT_COMPAT | ENT_SUBSTITUTE, 'utf-8', false);
} else {
$linkText = htmlspecialchars($linkText, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, 'utf-8', false);
}
}
}
}
$tagContent = $this->renderChildren();
if ($tagContent !== null) {
......@@ -98,7 +112,7 @@ class EmailViewHelper extends AbstractTagBasedViewHelper
$this->tag->setContent($linkText);
$this->tag->addAttribute('href', $linkHref, $escapeSpecialCharacters);
$this->tag->forceClosingTag(true);
$this->tag->addAttributes($attributes ?? []);
$this->tag->addAttributes($attributes, false);
return $this->tag->render();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment