Problem/Motivation
When inserting image as a link, the inserted code is empty, while it should be a link to an image, using the file title/alt as a link text.
Steps to reproduce
- Create an image upload field
- Enable option to insert it as a file link
- Edit content, upload an image
- To to insert a link to it - clicking "insert" will do nothing.
Proposed resolution
Update insert-link.html.twig:
Before:
{%
set attach = {
id: id,
attributes: {
title: [
'description',
],
},
content: [
'description',
'filename',
],
}
%}
<a href="{{ url }}"{% if class %} class="{{ class }}"{% endif %}{{ attributes }} data-insert-type="{{ field_type }}" data-insert-attach='{{ attach|json_encode() }}'></a>
After the fix:
{%
set attach = {
id: id,
attributes: {
title: [
'description',
'title',
'alt',
],
},
content: [
'description',
'title',
'alt',
'filename',
],
}
%}
<a href="{{ url }}"{% if class %} class="{{ class }}"{% endif %}{{ attributes }} data-insert-type="{{ field_type }}" data-insert-attach='{{ attach|json_encode() }}'></a>
Once the template is updated, an image from image field can be insert as a link to an original file and it works as long as the image has alt or title specified.
Comments
Comment #2
snater commentedThanks for submitting the issue. It appears to be a bug, because it should be possible to insert an image as a link without having to apply any changes. The idea of the
insert-link.html.twigtemplate though is to be specific for files, in the sense of being agnostic to image specifics. If image specific attributes are to be picked up, the idea would be to create a custom template override per (admin) theme.However, there was supposed to be a proper default with the link text being the file name. This does not work at the moment. The attached patch fixes the issue, so now the file name should be picked as the link text by default.
Comment #5
snater commentedFixed in 8.x-2.1 and 3.0.0-beta3.