In core/modules/editor/src/Form/EditorImageDialog.php,
The setting of maximum dimension of inline-image do not obtain correctly.
When set the dimension limit of inline-image to be 400x300 for basic html at "admin/config/content/formats/manage/basic_html", those setting value cannot obtain due incorrect array name.
In the image upload settings object,
it should be
$image_upload['max_dimensions']['width']
$image_upload['max_dimensions']['height']
BUT
it try to look for
$image_upload['dimensions']['max_width']
$image_upload['dimensions']['max_height']
In a result, the dimensions limit would always be ZERO, that make system do NOT reform the inline images.
Comment | File | Size | Author |
---|---|---|---|
#48 | 2628656-48.patch | 7.48 KB | thpoul |
#48 | interdiff-2628656-46-48.txt | 1.28 KB | thpoul |
#46 | 2628656-46.patch | 7.34 KB | thpoul |
#46 | interdiff-2628656-41-46.txt | 1.93 KB | thpoul |
#41 | 2628656-41.patch | 6.94 KB | thpoul |
Comments
Comment #2
Matt_five CreditAttribution: Matt_five commentedPatch applied.
Please check.
Comment #3
Wim LeersThank you!
This still needs test coverage.
Comment #4
Matt_five CreditAttribution: Matt_five commentedHi,
I don't know much about test coverage.
Do I need to submit a unit test of my patch according to "https://api.drupal.org/api/drupal/core!core.api.php/group/testing/8" ?
Comment #5
cilefen CreditAttribution: cilefen commented@Matt_five Yes, or a WebTest if that is appropriate. The test code should be added to subsequent patches.
Comment #6
Wim LeersComment #7
Matt_five CreditAttribution: Matt_five commented(EditorUploadImageRescaleTest.txt is wrong version, please refer to comment #8 for the correct file)
Hello,
I had created a new patch and WebTest.
Please remind that the WebTest is using the "standard" profile, it need longer time to run.
Since I cannot upload my test file "EditorImageDimensionTest.php" due to file type restriction, I rename the file to "EditorImageDimensionTest.txt". Please advice and review.
Moreover, I would like to talk other issue related to this fix.
1. Duplicate remind/error/warning message was shown when image just uploaded
---------------------------------------------------------
When the image cannot pass the validation (e.g. file extension restriction, file size limitation) or trigger scale down process, it would print the message twice. I search in Core issue queue and found #2346893 (https://www.drupal.org/node/2346893). I think the problem in the Editor image dialog form would be the issue related to #2346893. Therefore, I would not cover duplicate message issue in this patch.
2. Integration test for EditorImageDialog
---------------------------------------------------------
I found the issue #2395377 (https://www.drupal.org/node/2395377). I support that directly visit 'editor/dialog/image/basic_html/' would be one of the way to test the dialog form for specific functionality.
3. Invalid argument for file_validate_image_resolution
---------------------------------------------------------
Related to #2387011 (https://www.drupal.org/node/2387011)
When using new fields to transform "$image_upload['dimensions']['max_width'] and "$image_upload['dimensions']['max_height']" to String value, it would generate string with 'x' (e.g. "123x456") which would be processed by file_validate_image_resolution at file.module (line 423).
This patch:
file_validate_image_resolution at file.module (line 423):
Thank you.
Comment #8
Matt_five CreditAttribution: Matt_five commentedPrevious "EditorUploadImageRescaleTest.txt" is wrong version.
Comment #9
Matt_five CreditAttribution: Matt_five commentedComment #10
Matt_five CreditAttribution: Matt_five commentedComment #11
Matt_five CreditAttribution: Matt_five commentedComment #12
Wim LeersCan you please
git add /path/to/file
your newly written test, so that the new test is part of the patch? :)Comment #13
Matt_five CreditAttribution: Matt_five commentedThe new test file is included in the update patch.
Thanks.
Comment #14
aerozeppelin CreditAttribution: aerozeppelin commentedComment #16
Matt_five CreditAttribution: Matt_five commentedPlease find the updated patch.
Comment #17
Matt_five CreditAttribution: Matt_five commentedComment #18
Matt_five CreditAttribution: Matt_five commentedHi,
would anyone have advise for the issue ?
Comment #19
Matt_five CreditAttribution: Matt_five commentedComment #20
thpoul CreditAttribution: thpoul as a volunteer commentedTest only. Should fail!
Comment #21
thpoul CreditAttribution: thpoul as a volunteer commentedTrying to move this forward, hopefully in the right direction :)
Comment #24
Wim LeersLooking great! :) Only small remarks, to improve long-term maintainability of this, but overall this looks ready.
I'd make this into two asserts:
For cases 1 and 3, these steps aren't spelled out separately. I think we also shouldn't here.
I'd create a helper for these 4 lines, because you repeat them 3 times (once for every case).
Let's move these into the return statement itself directly. No need to first assign these to helper variables.
Nit: 4 spaces of indentation, should be 2.
Comment #25
thpoul CreditAttribution: thpoul as a volunteer commentedThank you for the review Wim! Here is the updated patch.
Comment #26
Wim LeersI think this test would benefit from some further refactoring, it'd help maintainability.
This is not "rescaling", it's just "scaling".
(It's easy for me to make that same mistake, because in Dutch it's "herschalen", literally "re-scale". It seems it's something similar in Greek — your native tongue.)
But look at
file_validate_image_resolution()
's documentation, it clearly says "scale".And it's
ScaleImageEffect
, notRescaleImageEffect
.This
drupalGet()
call can be moved into the helper.And
getUploadedImageDimensions()
can AFAICT be merged into it as well.So then you can have an
uploadImage()
helper method that returns the dimensions of the uploaded image. Makes sense, right? :)Comment #27
thpoul CreditAttribution: thpoul as a volunteer commentedHope I got this right :) Thank you once again!
Comment #28
Wim LeersTests scaling of uploaded images.
s/scale/scaling/
I think this can be made much simpler and clearer.
We're testing the same editor every time. So no need to call that out.
// Case 1: no max dimensions set: uploaded image not scaled.
// Case 2: max dimensions smaller than uploaded image: image scaled down.
// Case 3: max dimensions greater than uploaded image: image not scaled.
This is great. It gives precise, actionable information in the test output.
These are both imprecise (because
<=
is used) and does not give useful output. Please make this like the previously cited example (in the previous point).Perhaps
$this->assertNoRaw('The image was resized')
for cases 1 and 3?$image_basename can be calculated from $uri. So there's no need to pass this.
Then it also becomes unnecessary to return this. (See previous point.)
This is the only place where this is being called. So you can remove that helper method and just move its body in here.
4 spaces of indentation instead of 2.
Comment #29
thpoul CreditAttribution: thpoul at Pixual commentedThank you Wim. I made the proposed changes and also some nitpicks while I was reading the code again. I didn't add comments yet to the helper functions since I'm waiting to see what the review of #2644838-34: Add test coverage for the editor's max dimension setting, and fix its message when one dimension is unrestricted will be and will apply the same strategy here.
Comment #30
Wim LeersYou can totally hardcode this to
public
.This would have to be plural:
. But let's just copy the text from the class docblock.Why are you not able to use a precise expected width & height?
4 spaces of indentation instead of 2.
Comment #31
aerozeppelin CreditAttribution: aerozeppelin commentedUpdates as per #30.
Comment #32
thpoul CreditAttribution: thpoul at Pixual commentedThe problem I see after the comment of #33-3, is that the test was passing just by luck. The image is not rescaling for some reason.
The problem started from #29. From the following interdiff:
Changing
$uploaded_image_file = $this->container->get('image.factory')->get($uri);
withfixes allows the image to scale which confuses me a lot :/
Note: this patch will fail, I'm working on one that will pass.
Comment #33
thpoul CreditAttribution: thpoul at Pixual commentedTest passes, but I'm not happy with testing only the width. Waiting for @Wim Leers's suggestions
edit: I forgot a line commented out, but this patch still needs work so I won't post an other patch while waiting for a review.
Comment #36
Wim LeersClosed #2710843: Ckeditor Inline Images don't respect maximum dimensions as a duplicate of this.
I was waiting to review this one because I think it'll make sense to have the tests here in the same
*Test.php
file as #2644838: Add test coverage for the editor's max dimension setting, and fix its message when one dimension is unrestricted. So I'd like #2644838 to land first (it's been RTBC for a week).Review coming soon. Assigning to myself so I don't forget.
Comment #37
Matt_five CreditAttribution: Matt_five commentedsupport and thanks
Comment #38
Wim LeersAs of #2644838-52: Add test coverage for the editor's max dimension setting, and fix its message when one dimension is unrestricted, this issue is blocking #2644838: Add test coverage for the editor's max dimension setting, and fix its message when one dimension is unrestricted, so #36 no longer makes sense. Let's move this forward.
Comment #39
Wim LeersThis is a review based on what we just learned at #2644838-51: Add test coverage for the editor's max dimension setting, and fix its message when one dimension is unrestricted.
This check is over-zealous. It's not necessary to have both specified, it's sufficient to have either specified.
This
&&
should be||
.(See #2644838-51: Add test coverage for the editor's max dimension setting, and fix its message when one dimension is unrestricted.)
Oh, this actually provides test coverage for points #2644838-51: Add test coverage for the editor's max dimension setting, and fix its message when one dimension is unrestricted.3.1 and #2644838-51: Add test coverage for the editor's max dimension setting, and fix its message when one dimension is unrestricted .3.2!
What's missing, is test coverage for point #2644838-51: Add test coverage for the editor's max dimension setting, and fix its message when one dimension is unrestricted.3.3, which would then also have test coverage for the above remark.
Comment #40
Wim Leers#32:
Because
$uri
is the image to upload:public://image-test-transparent-indexed.gif
, and'public://inline-images/' . $path_parts['basename'];
is the uploaded image. That's a key difference!So all you need here is:
#33:
Do this instead:
That calculates the scaled height, matching the scaled change in width. (The scale operation preserves the aspect ratio, and this respects that too.)
That's it :)
Just duplicate what you're doing in case 2, but this time do
$max_height = $image_file_height - 5;
.Comment #41
thpoul CreditAttribution: thpoul at Pixual commentedThank you Wim for your review. Here is the patch!
Comment #43
thpoul CreditAttribution: thpoul at Pixual commentedWeird test failure. timplunkett issued a retest and it passed. Switching back to NR
Comment #44
Wim LeersNit: inconsistent.
These 3 helpers need documentation, much like we did in the related issue. Otherwise committers will mark this NW for that reason.
That's it! Then this is RTBC :)
Comment #45
Wim LeersComment #46
thpoul CreditAttribution: thpoul at Pixual commentedHere it is :)
Comment #47
Wim LeersSorry, you were a bit too fast I'm afraid :P
These are undefined.
These are wrong.
Comment #48
thpoul CreditAttribution: thpoul at Pixual commentedOops!
Comment #49
Wim LeersThanks!
Comment #50
alexpottCommitted f4a1d0c and pushed to 8.1.x and 8.2.x. Thanks!
Comment #53
Wim LeersSo glad this is finally fixed!