- Issue created by @prudloff
- π«π·France PhilY πͺπΊπ«π· Paris, France
You should use
{{ 'test@example.com'|obfuscateMail }}
- Status changed to Needs review
3 months ago 9:10am 17 May 2025 - π«π·France prudloff Lille
Yes, the obfuscateMail filter works. But the module also provides an Twig function and it is broken.
We should either remove the function or make it work. - π¨πSwitzerland weri
In general, there seem to be a few implementations with the wrong order of the defined function parameters of the interface ObfuscateMailInterface::getObfuscatedLink($email, array $params = [], $text = '')
/** * Returns an obfuscated link from an email address. * * @param string $email * Email address. * @param array $params * Optional parameters to be used by the a tag. * @param string $text * Optional text for the a tag innerHtml. * * @return array * Obfuscated email link render array. */ public function getObfuscatedLink($email, array $params = [], $text = '');
https://www.drupal.org/project/obfuscate/issues/3370295 π Link Label in Field Formatter is not working Active
- π«π·France prudloff Lille
It looks like it was broken by this change: https://git.drupalcode.org/project/obfuscate/-/commit/c8680a4edf71277cc3...
- First commit to issue fork.
- π©πͺGermany yannickoo Berlin
Hey together π I have also noticed that the Twig function did not work as expected.
My goal was to create an obfuscated email link for
info@example.com
with an extraclass
attribute for styling. Unfortunately the MR that has been created could not help me since there is no support for attributes even if the module itself could handle that :(After checking the code I figured out that we got a small mess here regarding the order of the arguments: Sometimes it was
$email, $params, $text
and somewhere else$email, $text, $params
.The MR I have created fixes
- The broken Twig function
- Wrong order for arguments
- Attribute support for Twig function
Example usages
Minimal example
{{ obfuscate('info@example.com') }}
β‘οΈ
<a href="mailto:info@example.com">info@example.com</a>
With link text
{{ obfuscate('info@example.com', 'Link text') }}
β‘οΈ
<a href="mailto:info@example.com">Link text</a>
With link attributes
{{ obfuscate('info@example.com', 'Link text', { class: 'font-bold' }) }}
β‘οΈ
<a href="mailto:info@example.com" class="font-bold">Link text</a>
- π¦πΊAustralia nigelcunningham Geelong
@yannickoo, would you use the function if it was fixed? I was thinking of removing it.
- π«π·France PhilY πͺπΊπ«π· Paris, France
I would use at least use the 'with link text' example and will for sure find some usage for the 'with link attributes' one π
- π©πͺGermany yannickoo Berlin
It is important for me to add classes for styling purposes directly on the link, therefore the flexible function is very useful π
- π¦πΊAustralia nigelcunningham Geelong
Thanks for the reply; I'll keep it then :)