Problem/Motivation
Media video files (but not remote video files) use the FileVideoFormatter.
This formatter's settings form includes options to set width and height attributes on the <video> element.
These fields are correctly set to be numeric- however they are both marked required. This means any displayed video will have these same fixed dimensions, regardless of an individual video's actual dimensions.
Although the video width can still be controlled with css, these fixed attributes can cause problems like extra white space between the video and the controls when the set size is a different aspect ratio than the video.
FileVideoFormatter was added in #1174892: File field formatters for rich media display with <video> and <audio> HTML5 elements.
Steps to reproduce
- Visit the Manage Display page for a Video Media type.
admin/structure/media/manage/video/display - Edit the Format settings by clicking the cog.
- Width and Height are both required.
Proposed resolution
Remove the #required attribute from both width and height in the settingsForm
core/modules/file/src/Plugin/Field/FieldFormatter/FileVideoFormatter.php
This will allow a browser to display a video at its natural aspect ratio.
- If neither dimension is provided, the video will be rendered in its original aspect ratio.
- If only width or height is provided, the video will use that dimension.
- If both width and height are provided, the video will be rendered with those dimensions.
Remaining tasks
- Create MR: Done - 5057
- Create change record: Done - https://www.drupal.org/node/3418545.
- Review
- Commit
User interface changes
Allows users to leave the width and height blank for a video
Before

After

API changes
NA
Data model changes
NA
Release notes snippet
NA
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | Afterpatch_dimentionfield.png | 20.29 KB | kanchan bhogade |
| #27 | Beforepatch_dimentionfield.png | 20.8 KB | kanchan bhogade |
| #27 | AfterPatch.mp4 | 4.75 MB | kanchan bhogade |
| #27 | Beforepatch.mp4 | 3.96 MB | kanchan bhogade |
Issue fork drupal-3245446
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:
Comments
Comment #2
zrpnrComment #3
zrpnrThis patch removes the #required attributes from width and height in the settings form.
These attributes are not checked in
FileVideoFormatterTestso that should still pass.I didn't see anywhere else that this formatter was being tested but maybe testbot will catch something...
Comment #4
cilefen commentedComment #5
schillerm commentedTested this on 9.3.x-dev site, went to /admin/structure/media/manage/video/display was able to reproduce problem (width and height required).
Applied #3 patch went back to same page .. width and height no longer mandatory. Emptied width and height values and saved changes, no error messages. Uploaded a test video and made a view for it, changed width and height all seems ok. Ran similar tests with a video on article page, all fine. Can see #required attribute has gone from settingsForm() in FileVideoFormatter.php.
Comment #6
schillerm commentedComment #7
alexpottI think we need to fix \Drupal\file\Plugin\Field\FieldFormatter\FileVideoFormatter::settingsSummary() to deal with this not being set and also \Drupal\file\Plugin\Field\FieldFormatter\FileVideoFormatter::prepareAttributes(). I think we should only set the attributes if they are set. It would be good to test the HTML outputted by the file formatter when only width or height is set and when neither is set.
Comment #13
dwwI just ran into this for a client. I opened an MR, committed #3 as the first commit, and pushed another commit to address most of @alexpott's concerns in #7. Doesn't expand test coverage, so tagging for that.
Comment #15
dwwSaving credit for authors (myself and @zrpnr) and reviewers (@schillerm and @alexpott).
Comment #17
guiu.rocafort.ferrerI added an additional functional test, checking that the width and height attributes are missing when the formatter settings have a null value in the width and height attributes.
I am removing the Needs tests tag, and changing the status to needs review.
Comment #18
smustgrave commentedMR appears to have a failure.
Comment #19
guiu.rocafort.ferrerThe pipeline error seems to be related to this other issue ( https://www.drupal.org/project/drupal/issues/3401988 ) and not with the merge request itself. The branch itself is mergeable, though.
Should we still merge the code back to the project ? Or should we make the pipeline run correctly first ?
IMO, this is a really small change, and it also have associated tests, so it should be safe to just accept the merge request.
The second option might require to merge the changes back to the issue branch, so the pipeline is updated with the fix from the issue, and then, push so it runs without hitting the error ? I am not completely sure about this.
Comment #21
akhil babuI have added one more test to validate the HTML outputted by the file formatter when only width or height is set.
Comment #23
akhil babuMoving back to needs review
Comment #24
akhil babuSadly, there is a failed test. Rebasing..
Comment #25
akhil babuAll tests passed 🎉
Comment #26
smustgrave commentedSeems close.
Since this is changing the current field formatter believe we will need a CR with screenshots. Screenshots could be added to the issue summary here too.
Comment #27
kanchan bhogade commentedHi,
I Have tested the latest MR !5057 on Drupal version 11.0
MR Applied successfully...
Testing steps"
Testing Result:
For the Media type -> video ->dimention field not mandatory
It can save black and videos displayed with actual size. Also able to set fixed dimensions as per requirement
Attaching screenshots and videos as #26
Comment #28
akhil babuThanks for testing @Kanchan Bhogade.
I have updated the issue summary and created a Draft change record: https://www.drupal.org/node/3418545
Comment #29
shweta__sharma commentedScreenshots are added in #27 so removing the tag also I reviewed the CR it seems fine. Leaving it to someone else to review.
Comment #30
smustgrave commentedCR seems good.
Cleaned up the issue summary as the remaining tasks aren't API changes.
Also screenshots belong in the User interface changes section.
Torn if this is a feature request but will leave as is.
Comment #31
larowlanIssue credits
Comment #32
larowlanHiding patch
Comment #33
larowlanLeft some MR comments
Comment #34
guiu.rocafort.ferrerHi @larowlan, thank you for your suggestions.
I changed the formatter summary text, so there is one line for each width / height attribute that has been set.
I also joined the tests for the different cases, only width, only height, both, and none, in the same test method, changing the field config and loading the page again in the same method.
Waiting to see if all the pipelines run smoothly.
Comment #35
guiu.rocafort.ferrerI realized the functional test for testing the multiple width, height, both, none cases was wrong.
Fixed that in last commit.
Comment #36
guiu.rocafort.ferrerComment #37
smustgrave commentedFeedback appears to be addressed
Comment #38
guiu.rocafort.ferrer@smustgrave sorry about that, i will do that in future ocasions. Thanks for pointing that out, i didn't know.
Comment #41
larowlanCommitted to 11.x and backported to 10.3.x
Published CR
Comment #43
wim leersLet's also update the config schema to match this change: #3425318: Update `type: field.formatter.settings.file_video` to match the validation logic in FileVideoFormatter's settings form.