Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Usage Milestone: Google Analytics Module google_analytics crossed 1,000 active installs. Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Release: GraphQL Compose Codegen 1.1.2 Minor update available for module graphql_compose_codegen (1.1.2). Release: Mapy.com 1.1.3 Minor update available for module mapycom (1.1.3). Release: Ckeditor5 entity browser 3.0.3 Minor update available for module ckeditor5_entity_browser (3.0.3). Release: Ckeditor5 entity browser 3.0.1 Minor update available for module ckeditor5_entity_browser (3.0.1). Release: Ckeditor5 entity browser 3.0.2 Minor update available for module ckeditor5_entity_browser (3.0.2). Release: Teamleader Integration 4.0.2 Minor update available for module teamleader (4.0.2). Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Obfuscate

335 sites Security covered Drupal 9–11
View on drupal.org

This module provides various methods to hide email addresses from bots, such as using HTML entities or ROT13 with CSS fallbacks. It can be applied globally, per text format, per field, or through a Twig filter and service.

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 with a CSS reversed text fallback, ...). It will rely on external vendors when available.

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

Installation

Use Composer.

composer require drupal/obfuscate:^1.0@alpha

Configuration

System wide

The system wide configuration is used by the text filter, service container and the Twig extension.

The obfuscation method can be defined via Configuration > Content authoring > Obfuscate (/admin/config/obfuscate).

Text format

Activate the obfuscation for the desired text formats ('Full HTML', ...).Configuration > Content authoring > Text formats and editors, then check Email address obfuscation filter.

Per field

The field configuration inherits from the system wide configuration as a default value and can be overridden per field instance.

View modes

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.

// Favor dependency injection to get the service
$obfuscateMail = \Drupal::service('obfuscate_mail');
$mail = '[email protected]';
$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 filter

Returns an obfuscated email link. Use case: while using a custom template for email fields or printing User entity email address.

{{ '[email protected]'|obfuscateMail }}

Roadmap

  • Add other methods of obfuscating email addresses.
  • Improve the text Filter.
  • 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

Depends on

Dependencies of the latest stable release

  • field Drupal core
  • filter Drupal core

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Apr 2025
Latest release
4 months ago
Releases (12 mo)
1
Maintenance
Active

Releases

Version Type Core Release date
2.0.2 Stable 9–11 Apr 22, 2026
2.0.1 Stable 9–10 Apr 2, 2025