Using Acquia DAM with Responsive Images

Created on 23 May 2023, about 1 year ago
Updated 31 May 2023, about 1 year ago

On our site we are using Responsive Images. I selected all the different sized image styles to be used by Acquia DAM. But when I select the Responsive image style for my image field and then select an image from the DAM, it always uses the full-size embed. So even on small mobile devices it is downloading the full size image from the DAM.

When I look at the source code for the page, I just see a single `` tag with a single `src` rather than an img tag using `srcset`.

Is there something else I need to configure to get this working with Responsive images?

πŸ’¬ Support request
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mpotter

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

Comments & Activities

  • Issue created by @mpotter
  • πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

    We have an internal ticket for this, I linked them up on our side. We will be picking it up this week or next.

    We needed a custom responsive image formatter. That was added before alt text was finalized. So we're missing setting the alt text in our field formatter.

  • πŸ‡ΊπŸ‡ΈUnited States mpotter

    Thanks for the quick answer. Look forward to seeing it and will be happy to test it. It's the remaining issue preventing us from using the DAM on our web site.

  • πŸ‡ΊπŸ‡ΈUnited States mpotter

    Oh, hmm, I think it's actually working already! I had missed a step and had not set up the display view modes for the DAM-Image media entity itself. In that display mode, for the "Asset Reference" in the Format option, instead of using "Embed Core" I see an option for "Acquia DAM Responsive Image". When I select that and point it to the correct image style, now it all works.

  • πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

    Oh, really? In my notes I took, I thought we needed some extra work in our render array.

    We have:

        $elements[] = [
          '#theme' => 'responsive_image',
          '#responsive_image_style_id' => $responsive_image_style ? $responsive_image_style->id() : '',
          '#uri' => $uri,
          '#cache' => [
            'tags' => $cache_tags,
          ],
          '#width' => $image_attributes['width'],
          '#height' => $image_attributes['height'],
        ];
     
    

    We're missing some tricks the normal field formatter has in template_preprocess_responsive_image_formatter

    $variables['responsive_image'] = [
      '#type' => 'responsive_image',
      '#responsive_image_style_id' => $variables['responsive_image_style_id'],
    ];
    $attributes['alt'] = $item->alt;
    $variables['responsive_image']['#attributes'] = $attributes; 
    

    So I assumed we needed to fetch the alt text ourselves and properly set it. I haven't yet manually verified, but this in my sprint which kicked off today so I'll be double checking.

  • πŸ‡ΊπŸ‡ΈUnited States mpotter

    Correct, the Alt Text is definitely not set. We are setting that in a preprocess from the image name. So still get that added when you can. But without the alt text it is still rendering a responsive image that works.

  • Status changed to Needs review about 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    199 pass
  • πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

    Here's a patch. @mpotter does this match to what you've done?

  • πŸ‡ΊπŸ‡ΈUnited States mpotter

    That patch seems reasonable to pull the Alt text from the mapped field from the DAM. In our case we didn't have any Alt Text field in the DAM itself and just created a preprocess function to use the Filename (without extension) as the Alt text for now.

  • Status changed to Fixed about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

    This was committed with https://git.drupalcode.org/project/acquia_dam/-/commit/8b005ec918fd1f7e1... and will be part of the next release!

    Thanks for helping debug @mpotter

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024