Moved attachment_icon logic to attachment.macro.html.twig

This commit is contained in:
Jan Böhmer 2022-10-09 20:49:24 +02:00
parent a01ed3acf6
commit 9adebc35c5
3 changed files with 21 additions and 22 deletions

View file

@ -17,4 +17,23 @@
{% trans %}attachment.create{% endtrans %}
</button>
</div>
{% endmacro %}
{% macro attachment_icon(attachment, attachment_helper, class = "fa-fw fas fa-3x", link = true) %}
{% set disabled = attachment.secure and not is_granted("show_secure", attachment) %}
{% if not attachment_helper or attachment_helper.fileExisting(attachment) %}
{% if link and not disabled %}
<a target="_blank" data-turbo="false" rel="noopener" href="{{ entity_url(attachment, 'file_view') }}">
{% endif %}
{% if attachment.picture %}
<img class="hoverpic" {{ stimulus_controller('elements/hoverpic') }} data-thumbnail="{{ entity_url(attachment, 'file_view') }}" src="{{ entity_url(attachment, 'file_view') }}">
{% else %}
<i class="text-dark {{ class }} {{ ext_to_fa_icon(attachment.extension) }}"></i>
{% endif %}
{% if link and not disabled %}
</a>
{% endif %}
{% elseif not attachment_helper.fileExisting(attachment) %}
<i class="{{ class }} fa-exclamation-triangle text-danger" title="{% trans %}attachment.file_not_found{% endtrans %}"></i>
{% endif %}
{% endmacro %}