Commit 3aafc2c2 authored by Sean Blommaert's avatar Sean Blommaert Committed by Sean B
Browse files

Issue #3293141 by smustgrave, mcortes19, seanB: Alt text no longer appear

parent 15120436
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -128,7 +128,7 @@ class EasyResponsiveImagesManager implements EasyResponsiveImagesManagerInterfac
   */
  public function getImagesByAspectRatio(string $uri, string $aspect_ratio): array {
    $images_configuration = $this->initialImagesConfiguration();
    $style_infos = $images_configuration[$aspect_ratio] ?? NULL;
    $style_infos = $images_configuration[$aspect_ratio] ?? [];
    $style_urls = [];

    foreach ($style_infos as $style_info) {
@@ -153,7 +153,7 @@ class EasyResponsiveImagesManager implements EasyResponsiveImagesManagerInterfac
   */
  public function getImagesByScale(string $uri): array {
    $images_configuration = $this->initialImagesConfiguration();
    $style_infos = $images_configuration['scale'] ?? NULL;
    $style_infos = $images_configuration['scale'] ?? [];
    $style_urls = [];

    foreach ($style_infos as $style_info) {
+5 −11
Original line number Diff line number Diff line
@@ -147,21 +147,14 @@ class EasyResponsiveImagesFormatter extends ImageFormatter {
   */
  public function viewElements(FieldItemListInterface $items, $langcode): array {
    $elements = parent::viewElements($items, $langcode);
    /** @var \Drupal\file\Entity\File[] $files */
    $files = $this->getEntitiesToView($items, $langcode);

    foreach ($elements as $delta => $element) {
      $elements[$delta]['#item_attributes'] = new Attribute();
      $elements[$delta]['#item_attributes']['class'] = ['easy_responsive_images'];
      $elements[$delta]['#theme'] = 'easy_responsive_images_formatter';

      // Get original image data. (non cropped, non processed) This is useful
      // when implementing lightbox plugins that show the original image.
      $elements[$delta]['#width'] = $element['#item']->getValue()['width'];
      $elements[$delta]['#height'] = $element['#item']->getValue()['height'];

      // Adding additional image attributes.
      $elements[$delta]['#alt'] = $element['#item']->getValue()['alt'];
      $elements[$delta]['#loading_method'] = $this->getSetting('image_loading')['attribute'] ?? 'lazy';
      $elements[$delta]['#item_attributes'] = new Attribute($elements[$delta]['#item_attributes']);
      $elements[$delta]['#item_attributes']->setAttribute('alt', $element['#item']->getValue()['alt'] ?? NULL);

      // Add image_handling and specific data for the type of handling.
      $elements[$delta]['#data']['image_handling'] = $this->getSetting('image_handling');
@@ -173,7 +166,7 @@ class EasyResponsiveImagesFormatter extends ImageFormatter {
            'aspect_ratio' => $this->getSetting('aspect_ratio'),
          ];
          $elements[$delta]['#srcset'] = $this->easyResponsiveImagesManager->getImagesByAspectRatio($elements[$delta]['#data']['uri'], $elements[$delta]['#data']['aspect_ratio']);
          $elements[$delta]['#src'] = $elements[$delta]['#srcset'][0]['url'];
          $elements[$delta]['#src'] = $elements[$delta]['#srcset'][0]['url'] ?? $this->fileUrlGenerator->generateString($files[$delta]->getFileUri());
          break;

        case 'scale':
@@ -182,6 +175,7 @@ class EasyResponsiveImagesFormatter extends ImageFormatter {
            'url' => $this->fileUrlGenerator->transformRelative($this->fileUrlGenerator->generateAbsoluteString($files[$delta]->getFileUri())),
          ];
          $elements[$delta]['#srcset'] = $this->easyResponsiveImagesManager->getImagesByScale($elements[$delta]['#data']['uri']);
          $elements[$delta]['#src'] = $elements[$delta]['#srcset'][0]['url'] ?? $this->fileUrlGenerator->generateString($files[$delta]->getFileUri());
          break;

        default:
+10 −17
Original line number Diff line number Diff line
{# --
{#
  /**
   * @file
   * Default theme implementation to display a easy responsive images.
   *
   * Available variables:
   * - url: An optional URL the image can be linked to.
   * - src: The transformed src tag for the image, using the smallest defined width.
   * - srcset[]: The srcset of the transformed image,
          consisting of transformed url, transformed width & calculated height (if aspect ratio is used), and the srcset_url
   * - loading_method: The loading attribute of the image.
   * - decoding_method: The decoding attribute of the image.
   * - fetch_priority: The fetch priority of the image.
   * - width: The original width of the image.
   * - height: The original height of the image.
   * - alt: The alt text for the image.
   * - src: The transformed src tag for the image, using the smallest defined
   *   width.
   * - srcset[]: The srcset of the transformed image, consisting of transformed
   *   url, transformed width & calculated height (if aspect ratio is used),
   *   and the srcset_url
   * - item_attributes[]: attributes for the wrapper
   * - data[]: json encoded drimage data object
   *
   * @see EasyResponsiveImagesFormatter
   *
   * @ingroup themeable
   */
-- #}
#}

{{ attach_library('easy_responsive_images/resizer') }}

@@ -31,10 +27,7 @@
{% endfor %}

<img
  {{ item_attributes }}
  src="{{ src }}"
  data-srcset="{{ easy_responsive_images_srcset|join(',') }}"
  loading="{{ loading_method }}"
  decoding="{{ decoding_method }}"
  fetchpriority="{{ fetch_priority }}"
  {{ item_attributes }}
  />