Insert image field image as a link

Created on 19 November 2023, 12 months ago
Updated 15 January 2024, 10 months ago

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

  1. Create an image upload field
  2. Enable option to insert it as a file link
  3. Edit content, upload an image
  4. 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.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Miscellaneous

Created by

🇵🇱Poland pawel.traczynski Warsaw

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024