Skip to content

Commit

Permalink
Merge pull request #88 from netgen/support-link-wrapper-attributes
Browse files Browse the repository at this point in the history
Add better support for link wrapper and add alt text fallback to cont…
  • Loading branch information
RandyCupic authored Nov 29, 2021
2 parents ab24984 + 27eb822 commit 03deacd
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion bundle/Resources/views/ngremotemedia_content_field.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# - string title: used as title if set, otherwise caption from the image is used
# - bool dimensions: if set to true, will add width and height to img tag. false by default.
# - string link_href: if set, will wrap img tag with link (<a> tag)
# - string link_target: default empty, example: '_blank'
# - string link_class: default empty, adds css class to the link
# - string link_title: default empty, adds title attribute to the link
#}
{% block ngremotemedia_field %}
{% set format = parameters.alias ?? parameters.format|default('') %}
Expand All @@ -23,13 +26,21 @@
{% set otherConst = constant('Netgen\\Bundle\\RemoteMediaBundle\\Core\\FieldType\\RemoteMedia\\Value::TYPE_OTHER') %}

{% set link_href = parameters.link_href|default('') %}
{% set link_target = parameters.link_target|default('') %}
{% set link_class = parameters.link_class|default('') %}
{% set link_title = parameters.link_title|default('') %}

{% if field.value.mediaType == imageConst %}
{% if parameters.alt_text is defined and parameters.alt_text is not empty %}
{% set alt_text = parameters.alt_text %}
{% else %}
{% set alt_text = field.value.metaData.alt_text|default('') %}
{% endif %}

{% if alt_text is empty %}
{% set alt_text = content.name %}
{% endif %}

{% if parameters.title is defined and parameters.title is not empty %}
{% set title = parameters.title %}
{% else %}
Expand All @@ -41,7 +52,11 @@
{% endif %}

{% if link_href is not empty %}
<a href="{{ link_href }}">
<a href="{{ link_href }}"
{% if link_target is not empty %}target="{{ link_target }}" {% if link_target == '_blank' %}rel="nofollow noopener noreferrer"{% endif %}{% endif %}
{% if link_class is not empty %}class="{{ link_class }}{% endif %}
{% if link_title is not empty %} title="{{ link_title }}" {% endif %}
aria-label="{{ alt_text }}" >
{% endif %}
{% if variation is defined and variation.url%}
Expand Down

0 comments on commit 03deacd

Please sign in to comment.