Commit e80e702d authored by David Suissa's avatar David Suissa
Browse files

Issue #3307068 by DYdave: Dropped support for Drupal 9.2 and removed '' from...

Issue #3307068 by DYdave: Dropped support for Drupal 9.2 and removed '' from class 'ImageLinkFormatter', since the property is now part of parent class 'ImageFormatter'.
parent 7b237f50
Loading
Loading
Loading
Loading
+4
Changes for composer.json: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -12,8 +12,12 @@
            "role": "Maintainer"
        }
    ],
    "minimum-stability": "dev",
    "support": {
        "issues": "https://www.drupal.org/project/issues/image_link_formatter",
        "source": "https://git.drupalcode.org/project/image_link_formatter"
    },
    "require": {
        "drupal/core": "^9.3 || ^10"
    }
}
+1 −1
Changes for image_link_formatter.info.yml: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ description: Extends Core 'image' formatter to allow displaying images wrapped w
package: Fields

type: module
core_version_requirement: ^9 || ^10
core_version_requirement: '^9.3 || ^10'

dependencies:
  - drupal:image
+28 −11
Changes for src/Plugin/Field/FieldFormatter/ImageLinkFormatter.php: 28 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -39,23 +39,40 @@ class ImageLinkFormatter extends ImageFormatter implements ContainerFactoryPlugi
  private $entityFieldManager;

  /**
   * The file URL generator.
   * Constructs an ImageLinkFormatter object.
   *
   * @var \Drupal\Core\File\FileUrlGeneratorInterface
   */
  protected $fileUrlGenerator;

  /**
   * {@inheritdoc}
   * @param string $plugin_id
   *   The plugin_id for the formatter.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
   *   The definition of the field to which the formatter is associated.
   * @param array $settings
   *   The formatter settings.
   * @param string $label
   *   The formatter label display setting.
   * @param string $view_mode
   *   The view mode.
   * @param array $third_party_settings
   *   Any third party settings.
   * @param \Drupal\Core\Session\AccountInterface $current_user
   *   The current user.
   * @param \Drupal\Core\Entity\EntityStorageInterface $image_style_storage
   *   The image style storage.
   * @param \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator
   *   The file URL generator.
   * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
   *   The entity field manager service.
   */
  public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, AccountInterface $current_user, EntityStorageInterface $image_style_storage, EntityFieldManagerInterface $entity_field_manager, FileUrlGeneratorInterface $file_url_generator) {
  public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, AccountInterface $current_user, EntityStorageInterface $image_style_storage, FileUrlGeneratorInterface $file_url_generator, EntityFieldManagerInterface $entity_field_manager) {
    parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings, $current_user, $image_style_storage, $file_url_generator);
    $this->entityFieldManager = $entity_field_manager;
    $this->fileUrlGenerator = $file_url_generator;
  }

  /**
   * {@inheritdoc}
   *
   * Adds the 'entity_field.manager' service to parent's container.
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static(
@@ -68,8 +85,8 @@ class ImageLinkFormatter extends ImageFormatter implements ContainerFactoryPlugi
      $configuration['third_party_settings'],
      $container->get('current_user'),
      $container->get('entity_type.manager')->getStorage('image_style'),
      $container->get('entity_field.manager'),
      $container->get('file_url_generator')
      $container->get('file_url_generator'),
      $container->get('entity_field.manager')
    );
  }

+2 −10
Changes for tests/src/Functional/ImageLinkFormatterTest.php: 2 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -67,11 +67,7 @@ class ImageLinkFormatterTest extends ImageFieldTestBase {

    // Test the formatter when the link field is empty.
    $output = $this->renderField($node, $image_field_name, $image_field_settings);
    // For core versions below 9.1.
    if (floatval(\Drupal::VERSION) < 9.1) {
      $this->assertEquals($output, '<img src="' . $file->createFileUrl() . '" width="40" height="20" alt="" />');
    }
    elseif (floatval(\Drupal::VERSION) < 9.4) {
    if (floatval(\Drupal::VERSION) < 9.4) {
      // Moving forward, attribute 'loading' is added by default, see #3173719.
      $this->assertEquals($output, '<img src="' . $file->createFileUrl() . '" width="40" height="20" alt="" loading="lazy" />');
    }
@@ -91,11 +87,7 @@ class ImageLinkFormatterTest extends ImageFieldTestBase {

    // Test the formatter when a link is present.
    $output = $this->renderField($node, $image_field_name, $image_field_settings);
    // For core versions below 9.1.
    if (floatval(\Drupal::VERSION) < 9.1) {
      $this->assertEquals($output, '<a href="http://example.com"><img src="' . $file->createFileUrl() . '" width="40" height="20" alt="" /></a>');
    }
    elseif (floatval(\Drupal::VERSION) < 9.4) {
    if (floatval(\Drupal::VERSION) < 9.4) {
      // Moving forward, attribute 'loading' is added by default, see #3173719.
      $this->assertEquals($output, '<a href="http://example.com"><img src="' . $file->createFileUrl() . '" width="40" height="20" alt="" loading="lazy" /></a>');
    }