Obfuscate

Component ID

2871369

Component name

Obfuscate

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Downloads

162

Component created

Component changed

Component body

Provides several email obfuscation methods that can be used through Field Formatter, text Filter, service container and Twig function.

Context

The initial goal of this module was to provide basic email obfuscation for the core Email field during the Drupal 8 development of the SpamSpan filter module.
The current development now focuses on providing several obfuscation methods (html entities, ROT13, CSS reversed text, ...) with documentation for the site builders. It will rely on packagist vendors when available.

The following posts are giving a good overview of the subject :

Installation

Use Composer.

composer require drupal/obfuscate

Configuration

Configuration for the text Filter, service container and Twig extension is system wide. The obfuscation method can be defined via /admin/config/obfuscate.

The field configuration inherits the system wide configuration as a default value. So field configuration can be overridden.

All the view modes (default / full, teaser, search index, ...) that exposes publicly email addresses should define the Field Formatter to Obfuscate.

For some reasons, it should be preferred to leave the Field Formatter of several view modes to Plain text or Email. So, the decision of obfuscating is left to the discretion of the site builder.

Service

Obfuscate can also be used from code via a service.

// Of course you will use dependency injection to get the service
$obfuscateMail = Drupal::service('obfuscate_mail');
$mail = 'terry.jones@spam.com';
$build = [
  '#markup' => $obfuscateMail->getObfuscatedLink($mail),
];

Service methods

getObfuscatedLink

Returns an obfuscated email link.

// Optional link parameters (html attributes) can be defined.
// If not overriden, provides the default rel="nofollow".
$params = ['class' => 'button'];
$obfuscateMail->getObfuscatedLink($mail, $params);

obfuscateEmail

Returns an obfuscated email link, it is used by the getObfuscatedLink method.

Twig function

{{ 'terry.jones@spam.com'|obfuscateMail }}

Browser support

@todo

Roadmap

  • Other methods of obfuscating email addresses.
  • Filter for WYSIWYG.
  • Twig helper {{ mail|obfuscateMail }}.
  • System wide obfuscation method configuration that applies to the Field Formatter, Filter and Twig extension.

Credits to Alexei Tenitski for the obfuscation solution on the first release.

Related modules

SpamSpan filter