/themes/contrib/bfd/templates/includes/footer.html.twig
wrap e-mail and encode
{# set email_footer variable #}{% set email_footer = 'mailto:' ~ drupal_token('site:mail') %}
{# value as variable #}{% set encoded_mail = email_footer | base64_encode %}{# Encodes mailto:e-mail to the set of symbols. #}
<i class="fas fa-envelope-open-text"></i> <span class="email"><a href="javascript:window.location.href=atob('{{ encoded_mail }}')">{{ drupal_token('site:mail') }}</a></span>
span.email {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.email a {
color: #843c39;
border: .5px dashed #fff;
border-radius: 17px;
box-shadow: 0 0 0 2px #050b0e, 2px 1px 4px 3px rgba(10, 10, 0, 0.5);
text-shadow: -1px -1px #530707;
padding-left: .2rem;
padding-right: .2rem;
}
base64_encode - is our new Twig-variable (must be declared)
How to inject base64_encode php-function?
(PHP 4, PHP 5, PHP 7, PHP 8)
base64_encode — Encodes data with MIME base64
base64_encode(string $string): string
Encodes the given string with base64.
This encoding is designed to make binary data survive transport through transport layers that are not 8-bit clean, such as mail bodies.
Base64-encoded data takes about 33% more space than the original data.
Extend Twig Extensions
1. Create directory base64_coding in /modules/contrib
mkdir /modules/contrib/base64_coding
tree
.
├── base64_coding.info.yml
├── base64_coding.services.yml
└── src
└── TwigExtension
└── Base64.php
2. base64_coding.info.yml
name: Custom Twig Filter - Base64 Coding
type: module
description: 'Provides text coding | decoding'
package: Core
core: '8.x'
core_version_requirement: ^8 || ^9 || ^103. base64_coding.services.yml
services:
base64_coding.twig_extension:
class: Drupal\base64_coding\TwigExtension\Base64
tags:
- { name: twig.extension }
arguments:
- '@entity_type.manager'4. /src/TwigExtension/Base64.php
<?php
namespace Drupal\base64_coding\TwigExtension;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
/**
* MyTwigExtension Base64 provides function and filter.
*/
class Base64 extends AbstractExtension {
public function getFilters()
{
return [
new TwigFilter('base64_encode', 'base64_encode'),
new TwigFilter('base64_decode', 'base64_decode'),
];
}
}
Enable newly created module
| Custom Twig Filter - Base64 Coding | Provides text coding | decoding |