EditorFileReference should maintain the aspect ratio of image if only one of the width or height is defined in embedded code

Created on 5 August 2024, 5 months ago

Problem/Motivation

NOTE:

This might be an edge case but I'd an issue anyway for reference.

if height or width or both are not set for an embedded image, \Drupal\editor\Plugin\Filter\EditorFileReference::process() computes height and width by inspecting the referenced file.
This can be a problem if one of the specified height or width is different than the file and other value is missing.

For eg. If the original image has 800x400 dimensions, and in code, the width is 600 then EditorFileReference::process() will set height as 600.

The reason I say this is edge case is because the site in which I encountered this issue, the problem was caused by an obsolete contrib module.

Steps to reproduce

Proposed resolution

Calculate missing height/width using the original aspect ratio.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.0 🔥

Component
Editor 

Last updated 3 days ago

Created by

🇮🇳India dipakmdhrm

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @dipakmdhrm
  • Merge request !9080Maintain aspect ratio. → (Open) created by dipakmdhrm
  • 🇮🇳India dipakmdhrm

    Patch for D10

  • Pipeline finished with Failed
    5 months ago
    Total: 148s
    #244501
  • 🇳🇿New Zealand quietone

    Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.

  • Pipeline finished with Success
    4 months ago
    Total: 392s
    #271457
  • Pipeline finished with Canceled
    4 months ago
    Total: 186s
    #271756
  • Pipeline finished with Success
    4 months ago
    #271759
  • Status changed to Needs review 4 months ago
  • Status changed to Needs work 4 months ago
  • 🇺🇸United States smustgrave

    Thank you for reporting.

    One of the next steps will be to get a test case added that shows the problem.

    Also can the steps to reproduce section be filled out please

  • First commit to issue fork.
  • 🇮🇳India vinmayiswamy

    Hi, I have added test cases to EditorFileReferenceFilterTest.php to validate the recent fix. These tests ensure that when only one dimension (width or height) is provided, the other dimension is correctly calculated to maintain the aspect ratio.

    Kindly review the changes and please let me know if any further adjustments are needed. Any feedback or suggestions for improvements are appreciated.

    Thanks!

  • Status changed to Needs review 3 months ago
  • 🇮🇳India vinmayiswamy

    Hi, I have updated the "Steps to Reproduce" section based on my understanding of the issue. Please review the changes and let me know if any further adjustments are needed. Thanks!

  • Pipeline finished with Success
    3 months ago
    Total: 197180s
    #286938
  • The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • 🇺🇸United States smustgrave

    False positive

  • Pipeline finished with Failed
    2 months ago
    Total: 163s
    #313381
  • The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • First commit to issue fork.
  • Pipeline finished with Success
    2 months ago
    Total: 921s
    #315645
  • 🇮🇳India mrinalini9 New Delhi

    Fixed phpstan and phpcs pipeline issues and updated the MR, please review it.

    Thanks!

  • 🇮🇳India vinmayiswamy

    Hi, I've addressed the feedback. Kindly please review. Thanks!

  • Pipeline finished with Success
    about 2 months ago
    Total: 582s
    #324158
  • Status changed to RTBC about 1 month ago
  • 🇺🇸United States smustgrave

    Believe feedback has been addressed for this one.

  • 🇳🇿New Zealand quietone

    I tested this today on a fresh install of Drupal 11.x, using the steps in the issue summary. I was not able to reproduce the problem. Is there a step missing? Without it failing it difficult to evaluate this change. Is this problem version specific? Would this change prevent deliberate change of the aspect ratio?

    I ran the test locally without the fix and it does fail. Is this only a problem when images are added programmatically?

    I left some comments in the MR for a bit of cleanup.

Production build 0.71.5 2024