Problem/Motivation
Currently there is no way to add the playsinline attribute on <video> elements being output by the new Drupal code Media module. The playsinline attribute is required for background video to work on iOS devices. (Note: a similar to the same issue filed on the file_entity project a few years ago – this one is specifically a reference to the core Drupal media entity and file formatter.)
Proposed resolution
- New checkbox should be added to the display options "plays inline".
- When selected a playsinline attribute is added to video tags
- Adds update hook and an ENTITY_TYPE_presave hook to ensure exported configuration stays in sync with the addition of the new property. See #43
Remaining tasks
None.
User interface changes
Adds a new checkbox to the "Manage display" options for the media video type.
Old situation:

New situation:

API changes
n/a
Data model changes
Adds playsinline to the media video schema.
Release notes snippet
Original report by chris_wearebraid
It would be excellent to add a playsinline option to media elements
| Comment | File | Size | Author |
|---|---|---|---|
| #85 | 3046152-85-D10.5-add-playsinline-option-video.patch | 12.99 KB | guillaumeg |
| #73 | 3046152-old.png | 69.15 KB | martijn de wit |
| #73 | 3046152-new.png | 71.81 KB | martijn de wit |
| #67 | 3046152-67-d10.4.patch | 85.89 KB | oways23 |
| #66 | Screenshot 2024-12-16 at 5.36.14 PM.png | 125.35 KB | smustgrave |
Issue fork drupal-3046152
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
chris_wearebraid commentedComment #3
chris_wearebraid commentedAlso hiding "Muted" option as well
Comment #4
chris_wearebraid commentedComment #5
chris_wearebraid commentedComment #7
pandaski commentedUseful attributes.
'muted' can be shared by both 'video' and 'audio' but 'playsinline' is for 'video'
Why not update the 'field.formatter.settings.file_video' and formatter?
Comment #8
jpschroeder commentedThe initial patch on this thread did work for Drupal < 8.7.2 but no longer works with drupal >= 8.7.2. Attached is an updated patch that also adds muted and playsinline attributes to video. It also implements a slightly different schema per Joseph Zhao's suggestion in #7
Comment #9
jpschroeder commentedComment #10
jpschroeder commentedComment #11
jpschroeder commentedComment #12
scottsawyerJust tested this on a site, works perfectly. Thank you for the patch.
Comment #13
aleevasAdded these new parameters to the tests
core/modules/file/tests/src/Functional/Formatter/FileVideoFormatterTest.phpFor version 8.8.x works perfectly
Comment #15
pandaski commentedWe need a test case here for the changes.
Comment #17
aleevasRerolled up to 8.9
And extended tests
Comment #18
pandaski commentedThanks for the test case.
@aleevas that patch looks good to me
Comment #19
alexpottmuted is already part of FileVideoFormatter so do we need to remove it from there. Ie is it relevant for Audio? It looks like it is - according to https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio. However as video already has the muted option moving this to the base formatter should be a separate issue from the playsinline work.
This is not part of the audio spec but it is part of the video spec so it should be part of \Drupal\file\Plugin\Field\FieldFormatter\FileVideoFormatter and not on the base class.
Comment #20
aleevas@alexpott thank you for review.
Ii this patch I've made fixes 1 and 2 points form previous comment.
But I'm not sure that I got the 3d point.
Could you please provide more information about this point?
Thanks!
Comment #21
alexpottLet's keep the blank line in between schemas it makes them easier to read.
Re #19.3 with this change if you have a videa media field and you go to the field formatter configuration screen after applying the code update and press save your configuration will change without you making any changes. That's because we're adding a new default setting -
playsinline => FALSE. So we need a post update function similar to field_post_update_email_widget_size_setting() (only in D8 code) that sets this new setting to the default value - ie.FALSE. We'll also need a test for the update function.Comment #22
alexpottActually now playsinline is not part of the base class this change is not necessary.
Comment #27
hchonovFixing the attribute prepartion for playsinline.
Comment #28
ranjith_kumar_k_u commentedFixed Cspell issue
Comment #29
mrshowermanSince there's #3090641: Add 'muted' configuration to audio field formatter. for the
mutedpart, shouldn't we reduce the scope of this issue and concentrate just on theplaysinlineattribute?Comment #31
rinku jacob 13 commentedI have tested the issue with drupal 9.5.x dev. Drupal 9.5.x alreday have muted option, but playsinline option is not there.After applying the patch #28, playsline shown the Format list. Adding Screenshots for the reference
Comment #32
rinku jacob 13 commentedComment #33
yashingole commentedComment #34
yashingole commentedVerified and tested patch #28 on Drupal 9.5.x-dev. Patch applied successfully and looks good to me.
Muted Checkbox was already present on 9.5.x. Screenshot is attached for reference:
Testing steps:
1. Install Media and Media Library module.
2. Navigate to Structure > Media Types > Edit Video.
3. Click on manage display.
4. Open the setting of the video file.
5. Observe the plays inline option is missing.
6. Apply the patch.
7. Observe that the Plays inline option appears.
Testing Result:
1. After applying the patch the plays inline checkbox along with muted checkbox is present.
Can be move to RTBC
Comment #37
martijn de witback to RTbC. Patch in D 10.1.x is green
Comment #39
rpayanmRandom test failure.
Comment #41
martijn de witComment #42
lubwn commentedApplying patch from #25 worked in my case as well. Tested on Drupal 9.5.
It is also worth noting that this functionality is crucial in accessibility. I was specifically searching for the solution because my videos refused to play on iphone devices. Having "autoplay" and "muted" is apparently not not enough for iphones and instead of at least showing the video with play button it simply decides to not render video at all, leaving the space blank. Adding "playsinline" from the patch actually solved the problem.
Comment #43
catchThis will change exported configuration for field formatters, but there's no update to keep things in sync. Needs a post update to update configuration in the database, but also the same logic should happen in hook_ENTITY_TYPE_presave() to cover importing default configuration from modules and profiles. Quite a few examples in core to look at, views or any other updates for config entities implement similar patterns.
The issue title mentions muted, but the patch doesn't, should it? #3090641: Add 'muted' configuration to audio field formatter. is for the audio formatter, not the video one.
Comment #44
agoradesign commented@catch muted is already configurable in the video formatter. I guess, it wasn't, when the issue was created
Comment #46
bvoynickUpdated issue title and summary
Comment #47
kostyashupenkoMuted is already added, this ticket was renamed to deliver only playsinline setting.
Patch #28 applies cleanly in 11.x. Let's review everything and finally merge
Comment #48
smustgrave commentedLooking at #28 noticed we will need an upgrade path + tests for the upgrade because of the schema changes.
Comment #49
rajab natshahDrupal 10.2.0 stable was released on: 16 Dec 2023 by: xjm
https://www.drupal.org/project/drupal/releases/10.2.0
Thank you, Drupal core team, and the Drupal Release team.
Re-roled the patch to work with Drupal 10.2.0
Comment #50
ahmad abbad commentedPatch #49 worked for me
Drupal 10.2.1
Comment #51
rajab natshahComment #54
rajab natshahAttached a static patch file for Drupal core 2024-06-20 10.3.x branch MR 8471, to use with composer patches
Comment #55
yeebot commentedPatch #54 works for me on Drupal 10.3.6.
Comment #57
kim.pepperAdded a post update hook and an entity presave as per #43.
Comment #58
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. 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.
Comment #59
kim.pepperChanged the post update hook to actually update the field formatter settings.
Comment #62
kim.pepperTests are green ✅ Ready for reviews
Comment #63
kim.pepperUpdated IS
Comment #64
smustgrave commentedSmall comment around upgrade path tests.
Comment #65
kim.pepperAdded upgrade test
Comment #66
smustgrave commentedAll feedback for this one appears to be addressed.
Applied the MR locally
Shouldn't the 2 checkboxes for "Muted" and "Plays inline" be above "Display of multiple files". almost missed them.
Comment #67
oways23 commentedRe-roll merge request #8472
Comment #68
mrshowermanRe #66: I agree that the 2 checkboxes should be moved, but since it concerns not only the new "Plays inline" box which this issue is about, but also the already existing "Muted", I'd vote for creating a separate issue for this to avoid scope creep.
We've been using this patch for a long time in various projects, and from my point of view, it is good to go.
Comment #70
oily commentedRebased and resolved merge conflict.
Comment #71
oily commentedComment #72
martijn de wittests are there. See #65
Agree that moving the checkboxes should be a follow up. Muted is already in core.
Comment #73
martijn de witAdded new images for the issue summary, to make the situation clear what is going to change.
Comment #74
smustgrave commentedStill think the form should be correct before merging. So will leave for others.
Comment #75
kim.pepper@smustgrave it's not as simple as moving the fields around. We need to merge the output from the parent
\Drupal\file\Plugin\Field\FieldFormatter\FileMediaFormatterBase::settingsForm(). Trying to splice it into the middle is going to make it pretty fragile imo.Comment #76
kim.pepperI've rebased this on 11.x. In my view this is ready.
Comment #77
smustgrave commentedWon't hold it up, just feel the form could use some love. That was the only outstanding thing from me.
Comment #78
alexpottSaving issue credit.
Comment #79
alexpottFixed on commit. Unfortunately #3420570: Misspellings in words used in schema files and elsewhere incorrectly removed autoplay from the dictionary.
Committed 46281c6 and pushed to 11.x. Thanks!
Comment #82
berdirThis added a file_file_video_presave() hook, but that's not a thing at all, because there's no such thing as a file_video entity type. It's also a legacy hook function.
I guess this should be a entity_view_display_presave() hook that checks for something using that formatter, but that's a lot of complexity for something as banal as fixing up a missing key in default config.
Comment #83
kim.pepperHmm. If it's not a hook then I assume it's not getting called. We already have a post-update hook for setting default values, so I guess it's dead code. Created a follow up #3533291: file_file_video_presave() attempts to update shipped configuration but doesn't work to remove.
Comment #84
catchIt's a bug in the upgrade path, reclassified #3533291: file_file_video_presave() attempts to update shipped configuration but doesn't work as a critical bug.
Comment #85
guillaumeg commentedRerolling the patch against Drupal 10.5 for those still using Drupal 10.
The content is the same as the last commit merged into 11.x, so the latest comments still apply, I guess.