Skip to content

Commit

Permalink
enable email obfuscation for ezemail content fields
Browse files Browse the repository at this point in the history
  • Loading branch information
René Hrdina committed Nov 16, 2018
1 parent 2e431ed commit 06430ba
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
4 changes: 2 additions & 2 deletions doc/README.md
Expand Up @@ -71,7 +71,7 @@ This bundle uses the twig filter of https://github.com/Propaganistas/Email-Obfus
```
'myadress@test.com'|obfuscateEmail
```
Therfore we provides a override of the ezrichtext fieldtype. Enable it with:
Therfore we provides overrides of the ezrichtext and ezemail fieldtypes. Enable them with:

Load the javascript fron the cdn or import it from the assets folder.

Expand All @@ -83,7 +83,7 @@ ezpublish:
site_group:
field_templates:
-
template: "StyleflashereZPlatFormBaseBundle:fields:ezrichtext.html.twig"
template: "StyleflashereZPlatFormBaseBundle:fields:content_fields.html.twig"
# Priority is optional (default is 0). The higher it is, the higher your template gets in the list.
priority: 10
```
Expand Down
31 changes: 31 additions & 0 deletions src/Resources/views/fields/content_fields.html.twig
@@ -0,0 +1,31 @@
{# The simple_block_field block is a shorthand html block-based fields (like eztext or ezrichtext) #}
{# You can define a field_value variable before rendering this one if you need special operation for rendering content (i.e. nl2br) #}
{# Block for field attributes rendering. Useful to add a custom class, id or whatever HTML attribute to the field markup #}
{% block field_attributes %}
{% spaceless %}
{% set attr = attr|default( {} ) %}
{% for attrname, attrvalue in attr %}{{ attrname }}="{{ attrvalue }}" {% endfor %}
{% endspaceless %}
{% endblock %}
{% block simple_block_field %}
{% spaceless %}
{% if field_value is not defined %}
{% set field_value = field.value %}
{% endif %}
<div {{ block( 'field_attributes' ) }}>
{% endspaceless %}{{ field_value|raw }}{% spaceless %}
</div>
{% endspaceless %}
{% endblock %}
{% block ezrichtext_field %}
{%- set field_value = field.value.xml|richtext_to_html5|obfuscateEmail -%}
{{ block( 'simple_block_field' ) }}
{% endblock %}
{% block ezemail_field %}
{% spaceless %}
{% if not ez_is_field_empty( content, field ) %}
{% set field_value = field.value.email %}
{{ ('<a href="mailto:' ~ field.value.email|escape( 'url' ) ~ '" ' ~ block( 'field_attributes' ) ~ '>' ~ field.value.email ~ '</a>')|obfuscateEmail }}
{% endif %}
{% endspaceless %}
{% endblock %}
25 changes: 2 additions & 23 deletions src/Resources/views/fields/ezrichtext.html.twig
@@ -1,23 +1,2 @@
{# The simple_block_field block is a shorthand html block-based fields (like eztext or ezrichtext) #}
{# You can define a field_value variable before rendering this one if you need special operation for rendering content (i.e. nl2br) #}
{# Block for field attributes rendering. Useful to add a custom class, id or whatever HTML attribute to the field markup #}
{% block field_attributes %}
{% spaceless %}
{% set attr = attr|default( {} ) %}
{% for attrname, attrvalue in attr %}{{ attrname }}="{{ attrvalue }}" {% endfor %}
{% endspaceless %}
{% endblock %}
{% block simple_block_field %}
{% spaceless %}
{% if field_value is not defined %}
{% set field_value = field.value %}
{% endif %}
<div {{ block( 'field_attributes' ) }}>
{% endspaceless %}{{ field_value|raw }}{% spaceless %}
</div>
{% endspaceless %}
{% endblock %}
{% block ezrichtext_field %}
{%- set field_value = field.value.xml|richtext_to_html5|obfuscateEmail -%}
{{ block( 'simple_block_field' ) }}
{% endblock %}
{# deprecated. include content_fields.html.twig directly, instead #}
{% include content_fields.html.twig %}

0 comments on commit 06430ba

Please sign in to comment.