Skip to content

Commit 03deacd

Browse files
authored
Merge pull request #88 from netgen/support-link-wrapper-attributes
Add better support for link wrapper and add alt text fallback to cont…
2 parents ab24984 + 27eb822 commit 03deacd

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

bundle/Resources/views/ngremotemedia_content_field.html.twig

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
# - string title: used as title if set, otherwise caption from the image is used
1414
# - bool dimensions: if set to true, will add width and height to img tag. false by default.
1515
# - string link_href: if set, will wrap img tag with link (<a> tag)
16+
# - string link_target: default empty, example: '_blank'
17+
# - string link_class: default empty, adds css class to the link
18+
# - string link_title: default empty, adds title attribute to the link
1619
#}
1720
{% block ngremotemedia_field %}
1821
{% set format = parameters.alias ?? parameters.format|default('') %}
@@ -23,13 +26,21 @@
2326
{% set otherConst = constant('Netgen\\Bundle\\RemoteMediaBundle\\Core\\FieldType\\RemoteMedia\\Value::TYPE_OTHER') %}
2427

2528
{% set link_href = parameters.link_href|default('') %}
29+
{% set link_target = parameters.link_target|default('') %}
30+
{% set link_class = parameters.link_class|default('') %}
31+
{% set link_title = parameters.link_title|default('') %}
2632

2733
{% if field.value.mediaType == imageConst %}
2834
{% if parameters.alt_text is defined and parameters.alt_text is not empty %}
2935
{% set alt_text = parameters.alt_text %}
3036
{% else %}
3137
{% set alt_text = field.value.metaData.alt_text|default('') %}
3238
{% endif %}
39+
40+
{% if alt_text is empty %}
41+
{% set alt_text = content.name %}
42+
{% endif %}
43+
3344
{% if parameters.title is defined and parameters.title is not empty %}
3445
{% set title = parameters.title %}
3546
{% else %}
@@ -41,7 +52,11 @@
4152
{% endif %}
4253

4354
{% if link_href is not empty %}
44-
<a href="{{ link_href }}">
55+
<a href="{{ link_href }}"
56+
{% if link_target is not empty %}target="{{ link_target }}" {% if link_target == '_blank' %}rel="nofollow noopener noreferrer"{% endif %}{% endif %}
57+
{% if link_class is not empty %}class="{{ link_class }}{% endif %}
58+
{% if link_title is not empty %} title="{{ link_title }}" {% endif %}
59+
aria-label="{{ alt_text }}" >
4560
{% endif %}
4661
4762
{% if variation is defined and variation.url%}

0 commit comments

Comments
 (0)