Closed (fixed)
Project:
Drupal core
Version:
9.5.x-dev
Component:
media system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
23 Dec 2021 at 22:01 UTC
Updated:
9 Jan 2023 at 14:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
heddnThis one is a little tricky, because the thumbnail formatter injects its own render into the constructor where the field uri generator should go.
Comment #3
heddnThis gets us started, but we probably need to do some fancy BC/deprecation dance-work.
Comment #4
murilohp commentedHey @heddn I think it's a good catch! I also think you forgot to document the new
$file_url_generatorvariable onMediaThumbnailFormatter.php. I'm uploading a new patch with the doc to see it the patch now applies on 9.3.I added a new tag for deprecated scenarios, I don't think it's a bug but let's see the opinion of other person.
Thanks!
Comment #5
berdirI'm wondering why tests didn't fail. Is it possible that this formatter has no test coverage?
Comment #6
murilohp commentedHey @berdir, I think you're right, we have tests for
OEmbedFormatterbut none forMediaThumbnailFormatter, good catch!I'll move this back to NW and add need tests tag here.
Thanks!!
Comment #7
murilohp commentedHey, I created a new test for
MediaThumbnailFormatter, I'll move this back to needs review to see what you guys think.Thanks!
Comment #8
murilohp commentedComment #9
heddnDo we really need a functional test? Wouldn't a kernel test be fine for our purposes here?
Comment #10
murilohp commentedHey @heddn, on the module we have two field formatters,
OEmbedFormatterandMediaThumbnailFormatter. The first one has a functional test to cover how the field would be rendered, my idea was to follow the same approach forMediaThumbnailFormatter.Comment #11
neclimdul#3264061: Remove deprecated functions from image module was committed so this should probably fail against 10.0.x.
Phpstan caught this locally. Looking forward to #3259355: Always do a full phpstan analysis on DrupalCI catching it first in CI though :-D
Comment #12
neclimdul👀
The fix makes sense. I didn't look too close at the test but I skim sort of makes sense and on 10.0.x the test fails without the fix but passes with it.
Comment #13
catchLooks like this will fix the following phpstan failure on full runs: https://www.drupal.org/pift-ci-job/2319582
Comment #15
catchCommitted 51c1ef6 and pushed to 10.0.x. Thanks!
Will cherry-picked to 9.4.x and 9.3.x after the freeze.
Comment #16
neclimdulExactly! Thanks for the speedy commit.
Comment #17
catchThinking about it more, I think the 9.4.x/9.3.x backport should include a 'best effort' deprecation with the constructor - i.e. handle both the old and new constructor arguments and trigger a deprecation if it's called with the old arguments. No need for deprecation test coverage etc. Since the 10.0.x patch represents the 'final' state we can just leave it as is.
Comment #18
catchComment #19
murilohp commented@catch, you mean something like this patch for 9.4.x/9.3.x backport?
Comment #20
murilohp commentedComment #21
neclimdulFileUrlGeneratorInterface $file_url_generator = NULL, RendererInterface $rendererOptional before required parameter? I think you'll have to remove the types from the two parameters in the signature and do some juggling if you're shifting arguments like this. It's not just the missing parameter but the parameter order that needs bc.
Comment #22
catchYep both arguments would have to have no type and default to null, then instanceof checks in the constructor to see what we're getting.
Comment #23
murilohp commentedThanks @neclimdul and @catch, maybe something like this is enough here.
Comment #24
daffie commentedThe added test is the same as the one committed to D10.
The parameters are added correctly.
For me it is RTBC.
Comment #27
catchCommitted/pushed to 9.4.x and cherry-picked to 9.3.x, thanks!
Comment #30
catchThis appears to have broken 9.4.x/9.3.x after commit, reverting for now.
Comment #31
xjmSee https://www.drupal.org/pift-ci-job/2324301 for an example of the test failures. They appear to be limited to PHP 7 environments.
Comment #32
neclimdulHave a theory about what's going on.
After this line the
$image['#printed'] === TRUEThis url change does nothing because render see's its already "printed" and does nothing giving an empty string.
Just reading the code everything seems pretty logical, but some that render array reference logic confused things. So this never tested what it thought but the question is why mink thinks asserting an empty string is OK in php8 and a failure in php7.
The fix is going to be just make a fresh image array. On top of printed, and the cached render information is already on the array and will be reused.
Comment #33
neclimdulThe answer to the mink question will blow your mind....
https://3v4l.org/VGB5j
Comment #34
xjm@neclimdul, WOW, lol. How is that the newer behavior?
It's like Xeno's paradox of strings or something. Like... empty string appears at position zero of a string? Then it must also be at position one. And every position. Actually, there are infinitely many empty strings in a string, by that logic. (Or, well, finite, but at least as many as there are possible substrings. Still bizarre.)
Comment #35
murilohp commentedThank you so much for bringing this up @neclimdul! Looking deeply here, the test is not actually testing what I really wanted.
I've refactored the test, so sorry about fails.
I'm uploading two patches, one for 9.3/9.4 and the other updates 10.0
FYI: My idea was to test the following scenario:
media_thumbnail_formattermediaornodeComment #37
murilohp commentedIt's weird, testing locally here(branch 9.3.x, php7.4 and phpunit 8.5.21) the test pass, moving back to NW.
Comment #38
berdirtestbot is running in a subfolder, that's why this doesn't match. build the url with $mediaImage->toUrl('edit-form')
Comment #39
murilohp commentedThanks for the help @berdir! Let's see now.
Comment #40
berdirthis is a somewhat strange mix of creating the media in the test code and the node through the UI, why not just create the node in the same way, then you don't need to do that preg match to find the node id. (Alternatively, use \Drupal\Tests\node\Traits\NodeCreationTrait::getNodeByTitle())
there is a second assert here, that one might be failing now?
Comment #41
murilohp commentedThanks again for the responses @berdir, regarding #40:
NodeCreationTrait::getNodeByTitle()instead of the preg match. If you have any other ideas about how to improve this test(without creating the media) please let me know.FYI: Once again I'm uploading two patches(D9 and D10) along with two interdiffs one for D9 and one for D10.
Comment #42
murilohp commentedComment #43
murilohp commentedOk, I've uploaded the patch with the same name in my test issue, let's see now with a different name.
Comment #45
xjmThis change should probably be minor-only since fixing the deprecation requires reordering the constructor arguments.
Comment #46
longwaveRemoving this blank line is out of scope. Otherwise the test change and deprecation fix look correct to me.
Comment #47
mrinalini9 commentedUpdated patch #43 by addressing #46, please review it.
Comment #48
longwaveThanks!
Oops, I forgot that these lines need to be updated to 9.5.0 instead of 9.3.0 now.
Comment #49
mrinalini9 commentedUpdated patch #47 as per mentioned in #48, please review it.
Comment #50
longwaveThanks again - #49 is good for 9.x and #43 for 10.x.
Comment #54
catchCommitted/pushed/cherry-picked to 10.1.x/10.0.x and 9.5.x respectively, thanks!
Comment #56
rwam commentedHi @catch,
the committed changes avoid applying an old patch for https://www.drupal.org/project/drupal/issues/2961404 so I have to create an updated patch for that issue. But I'd like to know if there is any chance to fix that issue because there are a lot of related issues with missing language handling in MediaThumbnailFormatter and ImageFormatter that are still active.
Cheers Ralf