Problem/Motivation
Maximum width and maximum height can be set for various media types such as video and photo. These are legitimate oembed request parameters which have a specific function.
The height and width values returned by the provider take into account the maximum size settings and aspect ratio of the resource. For example, if both "max width" and "max height" are set to 500, the "width" and "height" returned might be 500 and 300.
Reference: https://oembed.com/
Duplicate issue with a longer explanation: #3310520: oEmbed videos should use returned height and width values
Steps to reproduce
Current behaviour:
- When set to zero, the provider determines width and height and returns them in the response
- When set to non-zero, these are sent to the provider but the response is ignored. Instead, Drupal sets the dimensions to these exact values
Expected behaviour:
- When set to zero, the provider determines width and height and provides them in the response. Drupal sets the dimensions to the "height" and "width" values returned by the provider.
- When set to non-zero values, these are sent to the provider. Drupal sets the dimensions to the "height" and "width" values returned by the provider.
Proposed resolution
For height and width check resource width/height FIRST
Remaining tasks
NA
User interface changes
NA
API changes
NA
Data model changes
NA
Release notes snippet
When setting oEmbed width/height to 0, the provider width/height will be used.
Original report
From #2831944-227: Implement media source plugin for remote video via oEmbed:
Some oEmbed providers -- notably YouTube -- will completely ignore the max_width and max_height settings of the oEmbed formatter, which can result in a video overflowing a frame that is far too small for it, and that looks extremely weird. Therefore, given a max_width/height and the width/height of the resource, the formatter should choose whichever value is bigger.
Sounds like a pretty good idea, but it could introduce some weirdness and complexity under certain circumstances. This issue is to figure out if and how we should implement that.
| Comment | File | Size | Author |
|---|
Issue fork drupal-2966656
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 2966656-negotiate-max-widthheight
changes, plain diff MR !7041
Comments
Comment #2
phenaproximaThe main issue has landed, so let's have a look at this.
Comment #5
jds1I needed responsive YouTube embeds and they weren't working out of the box. I was able to get them working by unsetting the width/height attributes on the oembed wrapper iframe (the iframe that contains the youtube iframe) and adding some additional CSS to
.media-oembed-content.If this is the right approach I could work on a patch, but I'm definitely not thinking of any situations where the width/height on the parent oembed wrapper iframe could need set width/height attributes. Are there? Should we add a "responsive" checkbox to the field display config that removes width/height when checked? Am I out of scope for this issue/should I create a new one?
Thanks all.
Comment #6
phenaproxima@if-jds, I think you might want to take a look at #3061134: oEmbed videos are not fully responsive, where responsive videos are being worked on more comprehensively. This issue is a more low-level and is concerned with oEmbed providers which play fast and loose with the oEmbed specification.
Comment #15
wim leersClosed #3310520: oEmbed videos should use returned height and width values as a duplicate. Asked @imclean there to move his patch to this issue. Already going ahead and crediting them here! And @cilefen too, because thanks to him we discovered it was a duplicate :)
Also bumping to because this fits under — see https://www.drupal.org/docs/develop/issues/fields-and-other-parts-of-an-...
Comment #16
wim leersMore triaging:
Comment #17
imclean commentedThe only oEmbed type which doesn't include width and height parameters is Link. We should use the returned values where possible. The YouTube problem mentioned in the IS will need to be reviewed as well to see if anything has changed in 4 years.
Comment #18
imclean commentedThis will have at least 1 fail. I can't seem to get enough information from running the test locally, it just says "FATAL Drupal\Tests\media\Functional\FieldFormatter\OEmbedFormatterTest: test runner returned a non-zero error code (2)".
Comment #20
imclean commentedThis is probably due to this patch always using
->getWidth()etc. on Rich, Photo and Video types. This is valid so I'll have to look into it.This works fine locally (CLI). I can't see where the 480 comes from if it's requesting the video from Vimeo for the test.
Comment #21
imclean commentedI can't run JS tests yet and I'm having trouble getting a fully functional local test environment. I'm still not sure why run-tests.sh doesn't produce more information. The testbot doesn't really say anything either, probably because the assertions don't have a message.
It might be good to add some extra information to the tests, such as which selector it's using and the value it's trying to compare.
Comment #22
imclean commentedTest URL and return value.
https://vimeo.com/api/oembed.json?url=https://vimeo.com/7073899&maxwidth...
Comment #23
imclean commentedTwitter returns height and width but they're always null.
YouTube has minimum dimensions of 200 x 200.
Comment #24
imclean commentedComment #25
imclean commentedComment #27
imclean commentedI can't remember why I changed it 200, I was probably still working out what was testing what. I also couldn't see where the size of 240 was arrived at.
Comment #29
imclean commentedComment #30
imclean commentedUpdated the IS with what I think is the real problem here.
Comment #31
imclean commentedThe formatter settings.
Video without the patch. The video is slightly stretched in this case with the whitespace caused by the iFrame being set to 1000 x 1000.
Video after applying the patch. The iFrame is set to the size the returned by Vimeo.
Comment #32
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #33
imclean commentedComment #34
imclean commentedComment #35
smustgrave commentedTried testing this with 1000X1000 and the image appears zoomed in to me with the patch.
Comment #36
imclean commentedThis happens if you set the max_width too high for the region the video is in. I'm not sure what the media module should (or can) do here.
That said, it appears to be a thumbnail issue. I can replicate #35 but when I play the video it fits within the iFrame.
The thumbnail is a fixed width. This was handled in another issue - #3088168: Media thumbnail dimensions are wrong for YouTube videos.
Comment #37
smustgrave commentedSo this seems to be just Vimeo videos and not affecting YouTube ones. Using a Vimeo video I was able to replicate the same as #31.
Moving to NW for an issue summary to specifically call out what is the proposed solution. Might be worth noting this doesn't affect YouTube, even though the original post mentions this issue was primarily with YouTube videos.
Comment #38
imclean commentedI'm not sure what else I can add to this. The patch does what's described in the updated IS. Google has problems, there are a few issues around that. In this case, the thumbnail is the problem.
Plain embed:
https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=dPiLx...
With maxwidth and maxheight set:
https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=dPiLx...
The thumbnail size doesn't change, but that also doesn't fully explain the problem here.
Plain Google embed without Drupal has the thumbnail problem you describe in #35. Review the following at various browser widths:
https://www.youtube.com/embed/dPiLxdBOnTs
The Oembed spec states thumbnail dimensions must respect maxwidth and maxheight parameters, but clearly this isn't happening with YouTube.
(As an aside, Vimeo seems to handle responsive thumbnails well.)
What do you think we could do here to get around the problem with YouTube's thumbnails? I'd be happy to look into it, but I don't really have any suggestions, other than a theme or JS hack.
Comment #39
smustgrave commentedNo don’t need the thumbnail addressed here but I see the expected behavior in the IS but not what clear what was done to address it.
But if you think that’s not needed can remove the tag and put back into review also
Comment #40
imclean commentedThis is the key change in this issue and it affects all video providers.
$max_widthand$max_heightare the values set in the field formatter. These are sent to the oembed provider as the parametersmaxwidthandmaxheight.$resource->getWidth()and$resource->getHeight()are the values returned by the video provider, which take into account the values sent with the request.Before the patch the dimensions of the video were set to exactly the values of
$max_widthand$max_height.After the patch, the dimensions are set to the returned values
$resource->getWidth()and$resource->getHeight().It'd be nice to get a few more reviews here.
Comment #41
hudriI've tested patch #27 (can't use patch #34 because it does not apply on Drupal v10.0.x, but code in #34 looks pretty similar). The patch has errors when any dimension field is empty. Error log shows access denied, most likley due missing query parameter values.
Field formatter setting
width="1920", height=""causes an error:Path: /media/oembed?url=https%3A//www.youtube.com/watch.....&max_width=1920&max_height&hash=.....Field formatter setting
width="1920", height="1080"works:Path: /media/oembed?url=https%3A//www.youtube.com/watch.....&max_width=1920&max_height=1080&hash=.....UPDATE: This problem was not introduced by this patch, it also happens on an unpatched v10.0.4
Comment #42
imclean commented#41:
Comment #43
smustgrave commentedRetested following #31 and got the whitespace and with the patch I did not.
Also may somewhat be related to #3350299: Allow oEmbed video iFrames to expand to available space
Comment #45
imclean commentedCould this be related? #3332456: [random test failure] MediaTest::testLinkManualDecorator()
Comment #46
smustgrave commentedRandom ckeditor error.
Know spokje has been working on the random failures.
Comment #48
smustgrave commentedAppears to be unrelated failure.
Comment #50
longwaveThe patch and fix look good, but I think this needs a release note - this may change the size of embedded video on existing sites when they upgrade?
Comment #51
smustgrave commentedHiding patches for clarity
Updated issue summary with release note (not great at those)
Moved patch into MR.
Comment #53
smustgrave commentedTests are all green. Since this was previously RTBC going to restore status.
Comment #54
alexpott@nod_ has asked a question that needs answering on the MR.
Comment #55
smustgrave commentedTried the suggestion but the caused the tests to fail https://git.drupalcode.org/issue/drupal-2966656/-/jobs/1143627
So reverted back.
Comment #56
alexpottLet's add the comment @nod_ is suggesting
Comment #57
smustgrave commentedAdded comment.
Comment #60
nod_Thanks
Committed 5559dba and pushed to 11.x. Thanks!
Comment #62
damienmckennaFor anyone reading the comments via email (and not seeing the merge request updates), the change was also merged to the 10.3.x branch.