Problem/Motivation

The module always adds "alt" and "title" attributes for an image tag, even they are empty. I propose to skip these attributes if they are empty.

Proposed resolution

The easiest way is to update the theme_image_srcset() function. But I'm not sure that this update will not create other issues.
Another way is to refactor the theme_picture() (don't set 'alt' and 'title' keys if they are empty):

  if (variable_get('picture_fallback_method', 'src') === 'src') {
      $min_ie9_fallback = array(
        '#theme' => 'image_srcset',
        '#uri' => $src,
        '#alt' => isset($attributes['alt']) ? $attributes['alt'] : '',
        '#title' => isset($attributes['title']) ? $attributes['title'] : '',
        '#attributes' => array_diff_key($attributes, array('alt' => '', 'title' => '')),
      );
      $output[] = drupal_render($min_ie9_fallback);
    }
    else {
      // Fallback image for < IE9.
      $min_ie9_fallback = array(
        '#theme' => 'image_srcset',
        '#uri' => $src,
        '#alt' => isset($attributes['alt']) ? $attributes['alt'] : '',
        '#title' => isset($attributes['title']) ? $attributes['title'] : '',
        '#attributes' => array_diff_key($attributes, array('alt' => '', 'title' => '')),
      );
      $output[] = '<!--[if lt IE 9]>';
      $output[] = drupal_render($min_ie9_fallback);
      $output[] = '<![endif]-->';

      // Fallback image for > IE8.
      $srcset = array(
        'uri' => $src,
      );
      $dimensions_clone = $dimensions;
      picture_get_image_dimensions($variables['style_name'], $dimensions_clone);
      if (!empty($dimensions_clone['width'])) {
        $srcset['width'] = $dimensions_clone['width'] . 'w';
      }
      $plus_ie8_fallback = array(
        '#theme' => 'image_srcset',
        '#srcset' => array($srcset),
        '#alt' => isset($attributes['alt']) ? $attributes['alt'] : '',
        '#title' => isset($attributes['title']) ? $attributes['title'] : '',
        '#attributes' => array_diff_key($attributes, array('alt' => '', 'title' => '')),
      );
      $output[] = '<!--[if !lt IE 9]><!-->';
      $output[] = drupal_render($plus_ie8_fallback);
      $output[] = '<!-- <![endif]-->';
    }
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Chalk created an issue. See original summary.

Chalk’s picture

Status: Active » Needs review
FileSize
449 bytes

My quick solution is here.

krina.addweb’s picture

Status: Needs review » Reviewed & tested by the community

@Chalk,thanks for the patch it works correctly.

lesleyfernandes’s picture

Status: Reviewed & tested by the community » Closed (outdated)

I checked the codebase, and it is already fixed.