Problem/Motivation

Alt text does not appear for the images in the lightbox. An alt attribute is present on the thumbnail images, and there are some data attributes on the link referring to it, but the values don't get passed to the lightbox image. There is an empty alt tag there.

In addition, the aria-label for the link is set to the entire contents of data-gbox-img-attrs. That doesn't seem correct.

Steps to reproduce

Use the glightbox responsive formatter on a field.
Click on thumbnail image to open the lightbox.
Inspect the image and look for its alt attribute.

Proposed resolution

Something seems off in template_preprocess_glightbox_responsive_formatter. The data-gbox-img-attrs attribute is added to the variables and template markup, but I don't see how this is used. Seems like we need to set the data-alt attribute or add the alt to the list of values for data-glightbox attribute.

Remaining tasks

Refactor template_preprocess_glightbox_responsive_formatter to add all the img attributes/data options correctly so that glightbox can use them.

User interface changes

none

API changes

none

Data model changes

none

CommentFileSizeAuthor
#3 image 3.png63.9 KBlevmyshkin
#3 image 2.png221.98 KBlevmyshkin
#3 image 1.png72.87 KBlevmyshkin

Issue fork glightbox-3532876

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

heatherwoz created an issue. See original summary.

heatherwoz’s picture

Issue summary: View changes
levmyshkin’s picture

StatusFileSize
new72.87 KB
new221.98 KB
new63.9 KB

Hi heatherwoz, I checked Responsive image with Content Type > Media (multiple values) > Image field and description is working:

fields

glightbox

But you are right, I cloned Colorbox module and moved 'data-gbox-img-attributes' instead of 'data-cbox-img-attributes' from Colorbox. GLightbox uses data-glightbox attribute with 'title' and 'description' values:

https://github.com/biati-digital/glightbox?tab=readme-ov-file#examples

Also you can check that you use common tags for description, because it's filtering for XSS:

img-attributes

I need to know your struction of content type, images can be in different nested entity types, for example:
Content type > Paragraph field > Media > Image
Content type > Paragraph field (gallery) > Pagraph field (gallery item) > Media > Image
Content type > Paragraph field > Image
Content type > Paragraph field (gallery) > Pagraph field (gallery item) > Image

It's impossible to predict all possible structures and nested levels for images, so I fetched few most common structures for captions.
https://www.drupal.org/project/glightbox/issues/3487478
https://www.drupal.org/project/glightbox/issues/3511270
https://www.drupal.org/project/glightbox/issues/3492657

If you describe your structure, I will add your case as well.

levmyshkin’s picture

Status: Active » Postponed (maintainer needs more info)
heatherwoz’s picture

Thanks for your reply.

The caption and description are working. It is the `alt` attribute on the `img` tag that is missing. I expect it to be there for accessibility. Someone could create a light box that does not include captions or descriptions, and assistive technology would need alt text to describe the image.

Our particular case is Custom Block > Media > Image.

albertho425’s picture

I am also experiencing the issue where ALT text is not displaying for an image that has ALT text. In my use case, I am using it in Drupal 10 Gutenberg editor for core and custom Gutenberg blocks.

I tried adding glightbox via contrib module and installing glightbox manually via my custom Gutenberg blocks library. In both cases, no ALT text for images that have ALT text.

  • levmyshkin committed f11907d0 on 1.0.x
    Issue #3532876 by heatherwoz, levmyshkin: Alt text missing on lightbox...
levmyshkin’s picture

Hi heatherwoz, albertho425, I added data-alt attribute in <a class="glightbox"> links with text from Caption. I'm not sure if you need additional separate field for alt attribute. Usually it should be enough to have something meaningful in alt="" attribute. And I removed aria-label from <a> tag, it's not button or <span>, so "title" attribute is enough for that. You can try dev version of the module or I will add a new module version later on this week.

levmyshkin’s picture

Status: Postponed (maintainer needs more info) » Needs review

heatherwoz’s picture

Thanks @levmyshkin

That solution doesn't work for us, because captions are optional, and sometimes users don't enter them. They are also highly configurable by this module.

I think a better approach is to use the alt text from the image itself. Drupal includes an alt text field on its image fields, so we can reasonably expect this to be filled out. I have opened an MR to show what I am thinking. I also removed all the references to $data-gbox-img-attributes since that is not used with GLightbox the same way it was with Colorbox.

albertho425’s picture

Thanks @levmyshkin and @heatherwoz. I agree with Heather of using the ALT text from the image itself. In my case, images in Gutenberg are required for saving.

levmyshkin’s picture

Hi heatherwoz, albertho425, thank you for your MR! I merged it and released Glightbox 1.0.18:
https://www.drupal.org/project/glightbox/releases/1.0.18

It looks fine for me:
https://drupalbook.org/ept/demo/video-and-image-gallery
https://drupalbook.org/ept/demo/image-gallery

levmyshkin’s picture

Status: Needs review » Fixed
levmyshkin’s picture

Status: Fixed » Closed (fixed)
heatherwoz’s picture

Thanks for the prompt response! I will try out the new release and open a new issue if we encounter any problems.

albertho425’s picture

Thank you both. We'll try it on Sunday and submit a new ticket if we encounter any issues. Thanks.