Commit 84b73fcf authored by Luke Leber's avatar Luke Leber
Browse files

Issue #3253676 by Luke.Leber: Remove Drupal 8 support and deprecate contrib webp module integration

parent caf54d38
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
@@ -12,12 +12,6 @@
        }
    ],
    "require": {
        "drupal/core": "^8.9 || ^9"
    },
    "require-dev": {
        "drupal/webp": "^1.0"
    },
    "suggest": {
        "drupal/webp": "Creates a WebP copy of image style derivatives to decrease loading times."
        "drupal/core": "^9.3"
    }
}
+1 −1
Original line number Diff line number Diff line
name: Responsive Image Preload
description: Allows responsive images to be preloaded.
type: module
core_version_requirement: ^8 || ^9
core_version_requirement: ^9.3
package: Media
dependencies:
  - drupal:responsive_image
+0 −1
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ services:
      - '@breakpoint.manager'
      - '@entity_type.manager'
      - '@image.factory'
      - '@module_handler'

  responsive_image_preload.third_party_settings:
    class: \Drupal\responsive_image_preload\ThirdPartySettings
+1 −22
Original line number Diff line number Diff line
@@ -38,13 +38,6 @@ class PreloadGenerator implements PreloadGeneratorInterface {
   */
  protected $imageFactory;

  /**
   * The module handler service.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * Creates a preload generator service instance.
   *
@@ -54,14 +47,11 @@ class PreloadGenerator implements PreloadGeneratorInterface {
   *   The entity type manager service.
   * @param \Drupal\Core\Image\ImageFactory $image_factory
   *   The image factory service.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler service.
   */
  public function __construct(BreakpointManagerInterface $breakpoint_manager, EntityTypeManagerInterface $entity_type_manager, ImageFactory $image_factory, ModuleHandlerInterface $module_handler) {
  public function __construct(BreakpointManagerInterface $breakpoint_manager, EntityTypeManagerInterface $entity_type_manager, ImageFactory $image_factory) {
    $this->breakpointManager = $breakpoint_manager;
    $this->entityTypeManager = $entity_type_manager;
    $this->imageFactory = $image_factory;
    $this->moduleHandler = $module_handler;
  }

  /**
@@ -133,10 +123,6 @@ class PreloadGenerator implements PreloadGeneratorInterface {
                $image_style = $image_style_storage->load($image_style_name);
                $image_url = file_url_transform_relative(file_create_url($image_style->buildUrl($file->getFileUri())));

                if ($this->moduleHandler->moduleExists('webp')) {
                  $image_url = preg_replace('/\.(png|jpg|jpeg)(\\?.*?)?(,| |$)/i', '.webp\\2\\3', $image_url);
                }

                $src_value[(int) $dimensions['width']] = $image_url . ' ' . $dimensions['width'] . 'w';
              }
              break;
@@ -147,9 +133,6 @@ class PreloadGenerator implements PreloadGeneratorInterface {
              $image_style = $image_style_storage->load($image_style_name);
              $image_url = file_url_transform_relative(file_create_url($image_style->buildUrl($file->getFileUri())));

              if ($this->moduleHandler->moduleExists('webp')) {
                $image_url = preg_replace('/\.(png|jpg|jpeg)(\\?.*?)?(,| |$)/i', '.webp\\2\\3', $image_url);
              }
              $src_value[(int) (mb_substr($multiplier, 0, -1) * 100)] = $image_url . ' ' . $multiplier;
              break;
          }
@@ -165,10 +148,6 @@ class PreloadGenerator implements PreloadGeneratorInterface {
            ],
          ];

          if ($this->moduleHandler->moduleExists('webp')) {
            $preload['#attributes']['type'] = 'image/webp';
          }

          if ($media_query = $breakpoint->getMediaQuery()) {
            $preload['#attributes']['media'] = $media_query;
          }
+0 −55
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\responsive_image_preload\Functional;

/**
 * Contains test cases for complex responsive image style configurations.
 *
 * @group responsive_image_preload
 */
class ResponsiveImagePreloadWebpTest extends ResponsiveImagePreloadBrowserTestBase {

  /**
   * {@inheritdoc}
   *
   * This is required because the webp module does not define a config schema.
   */
  protected $strictConfigSchema = FALSE;

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'entity_test',
    'breakpoint',
    'image',
    'responsive_image',
    'responsive_image_preload',
    'responsive_image_preload_test',
    'webp',
  ];

  /**
   * Tests that correct preloads are generated in a variety of configurations.
   *
   * @throws \Drupal\Core\Entity\EntityStorageException
   *   This should never happen under normal circumstances.
   * @throws \Drupal\Core\Entity\EntityMalformedException
   *   This should never happen under normal circumstances.
   */
  public function testResponsiveImageWebpPreload() {
    $this->drupalLogin($this->createUser([], NULL, TRUE));

    // Test case with no expected preloads.
    $this->setFormatterSettings('test1', TRUE);
    $this->drupalGet($this->entity->toUrl());

    $page = $this->getSession()->getPage();
    $preloads = $page->findAll('css', 'link[rel="preload"]');

    foreach ($preloads as $preload) {
      static::assertEquals('image/webp', $preload->getAttribute('type'));
    }
  }

}