Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] add subject and body to email viewhelper #3385

Open
wants to merge 1 commit into
base: 9.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion Neos.FluidAdaptor/Classes/ViewHelpers/Link/EmailViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* <a href="mailto:[email protected]">some custom content</a>
* </output>
*
* you may optionally add a subject and a body to the VH
* @api
*/
class EmailViewHelper extends AbstractTagBasedViewHelper
Expand All @@ -55,6 +56,8 @@ public function initializeArguments()
$this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
$this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
$this->registerArgument('email', 'string', 'The email address to be turned into a link.', true);
$this->registerArgument('subject', 'string', 'The subject of the email link.');
$this->registerArgument('body', 'string', 'The body of the email link.');
}

/**
Expand All @@ -65,7 +68,12 @@ public function render()
{
$email = $this->arguments['email'];

$linkHref = 'mailto:' . $email;
$linkHref = $this->getMailtoLink(
[$email],
$this->arguments['subject'] ?? '',
$this->arguments['body'] ?? ''
);

$linkText = $email;
$tagContent = $this->renderChildren();
if ($tagContent !== null) {
Expand All @@ -77,4 +85,17 @@ public function render()

return $this->tag->render();
}

protected function getMailtoLink(array $recipients, string $subject, string $body)
{
$recipientsString = implode( ',', $recipients);
$link = 'mailto:' . rawurldecode($recipientsString) . '?';
if ($subject !== '') {
$link .= 'subject=' . rawurlencode($subject);
}
if ($body !== '') {
$link .= '&body=' . rawurlencode($body);
}
return $link;
}
}
Loading