Verified Commit 96728e54 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Revert "Issue #3173180 by heddn, edysmp, chrisfree, andypost, markdorison,...

Revert "Issue #3173180 by heddn, edysmp, chrisfree, andypost, markdorison, anmolgoyal74, kiwimind, rkoller, ranjith_kumar_k_u, nod_, Fabianx, prudloff, quietone: Add UI for 'loading' html attribute to images"

This reverts commit 9de5949b.
parent 6e58ed88
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
@@ -147,13 +147,7 @@ public function testEntityDisplaySettings() {
    // Test the image field formatter settings.
    $expected['weight'] = 9;
    $expected['type'] = 'image';
    $expected['settings'] = [
      'image_link' => '',
      'image_style' => '',
      'image_loading' => [
        'attribute' => 'lazy',
      ],
    ];
    $expected['settings'] = ['image_link' => '', 'image_style' => ''];
    $component = $display->getComponent('field_test_imagefield');
    $this->assertSame($expected, $component);
    $display = EntityViewDisplay::load('node.story.teaser');
+0 −7
Original line number Diff line number Diff line
@@ -142,13 +142,6 @@ field.formatter.settings.image:
    image_style:
      type: string
      label: 'Image style'
    image_loading:
      type: mapping
      label: 'Image loading settings'
      mapping:
        attribute:
          type: string
          label: 'Loading attribute'

field.formatter.settings.image_url:
  type: mapping
+0 −11
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@
 * Exposes global functionality for creating image styles.
 */

use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Routing\RouteMatchInterface;
@@ -15,7 +14,6 @@
use Drupal\field\FieldStorageConfigInterface;
use Drupal\file\FileInterface;
use Drupal\image\Entity\ImageStyle;
use Drupal\image\ImageConfigUpdater;

/**
 * The name of the query parameter for image derivative tokens.
@@ -370,15 +368,6 @@ function image_entity_presave(EntityInterface $entity) {
  $entity->setSetting('default_image', $default_image);
}

/**
 * Implements hook_ENTITY_TYPE_presave() for entity_view_display.
 */
function image_entity_view_display_presave(EntityViewDisplayInterface $view_display): void {
  $config_updater = \Drupal::classResolver(ImageConfigUpdater::class);
  assert($config_updater instanceof ImageConfigUpdater);
  $config_updater->processImageLazyLoad($view_display);
}

/**
 * Implements hook_ENTITY_TYPE_update() for 'field_storage_config'.
 */
+0 −14
Original line number Diff line number Diff line
@@ -5,10 +5,6 @@
 * Post-update functions for Image.
 */

use Drupal\Core\Config\Entity\ConfigEntityUpdater;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\image\ImageConfigUpdater;

/**
 * Implements hook_removed_post_updates().
 */
@@ -18,13 +14,3 @@ function image_removed_post_updates() {
    'image_post_update_scale_and_crop_effect_add_anchor' => '9.0.0',
  ];
}

/**
 * Add the image loading attribute setting to image field formatter instances.
 */
function image_post_update_image_loading_attribute(array &$sandbox = NULL): void {
  $image_config_updater = \Drupal::classResolver(ImageConfigUpdater::class);
  \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'entity_view_display', function (EntityViewDisplayInterface $view_display) use ($image_config_updater): bool {
    return $image_config_updater->processImageLazyLoad($view_display);
  });
}
+0 −43
Original line number Diff line number Diff line
<?php

namespace Drupal\image;

use Drupal\Core\Entity\Display\EntityViewDisplayInterface;

/**
 * Provides a BC layer for modules providing old configurations.
 *
 * @internal
 *   This class is only meant to fix outdated image configuration and its
 *   methods should not be invoked directly. It will be removed once all the
 *   deprecated methods have been removed.
 */
final class ImageConfigUpdater {

  /**
   * Re-order mappings by breakpoint ID and descending numeric multiplier order.
   *
   * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display
   *   The view display.
   *
   * @return bool
   *   Whether the display was updated.
   */
  public function processImageLazyLoad(EntityViewDisplayInterface $view_display): bool {
    $changed = FALSE;

    foreach ($view_display->getComponents() as $field => $component) {
      if (isset($component['type'])
        && ($component['type'] === 'image')
        && !array_key_exists('image_loading', $component['settings'])
      ) {
        $component['settings']['image_loading']['attribute'] = 'lazy';
        $view_display->setComponent($field, $component);
        $changed = TRUE;
      }
    }

    return $changed;
  }

}
Loading