Obfuscate


This project is not covered by Drupal’s security advisory policy.

Obfuscate field formatter

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

Supporting organizations: 

Obfuscate项目的Drush安装命令:复制到剪贴板

注:个别模块仍需开启相关子模块。
周安装量: 
7
维护状态: 
最低限度维护
开发状态: 
积极开发中

开发版本下载:

版本下载地址发布日期发布说明翻译下载
8.x-1.x-devtar.gz (13.04 KB) | zip (22.12 KB)2017年9月14日发布说明简 | 繁 | 更多