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:
Screenshot of the old checkboxes
New situation:
Screenshot of the new checkboxes

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

Issue fork drupal-3046152

Command icon 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

chris_wearebraid created an issue. See original summary.

chris_wearebraid’s picture

StatusFileSize
new2.36 KB
chris_wearebraid’s picture

StatusFileSize
new2.67 KB

Also hiding "Muted" option as well

chris_wearebraid’s picture

StatusFileSize
new3.22 KB
chris_wearebraid’s picture

Title: Video media needs playsinline option » Video media needs playsinline & muted options
Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: 3046152-add-playsinline-muted-option-video.patch, failed testing. View results

pandaski’s picture

Useful 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?

field.formatter.settings.file_video:
  type: file.formatter.media
  label: 'Video file display format settings'
  mapping:
    muted:
      type: boolean
      label: 'Muted'
    width:
      type: integer
      label: 'Width'
    height:
      type: integer
      label: 'Height'
jpschroeder’s picture

The 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

jpschroeder’s picture

jpschroeder’s picture

Version: 8.8.x-dev » 8.7.x-dev
jpschroeder’s picture

Issue summary: View changes
scottsawyer’s picture

Just tested this on a site, works perfectly. Thank you for the patch.

aleevas’s picture

Version: 8.7.x-dev » 8.8.x-dev
Status: Needs work » Needs review
StatusFileSize
new4.25 KB
new3.07 KB

Added these new parameters to the tests core/modules/file/tests/src/Functional/Formatter/FileVideoFormatterTest.php
For version 8.8.x works perfectly

Status: Needs review » Needs work

The last submitted patch, 13: 3046152-13.patch, failed testing. View results

pandaski’s picture

We need a test case here for the changes.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

aleevas’s picture

Status: Needs work » Needs review
StatusFileSize
new4.68 KB
new2.84 KB

Rerolled up to 8.9
And extended tests

pandaski’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/file/tests/src/Functional/Formatter/FileVideoFormatterTest.php
@@ -98,6 +99,7 @@ public function testAttributes() {
+    $assert_session->elementExists('css', "video[playsinline='playsinline'] > source[src='$file_url'][type='video/mp4']");

Thanks for the test case.

@aleevas that patch looks good to me

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/file/src/Plugin/Field/FieldFormatter/FileMediaFormatterBase.php
    @@ -56,6 +58,16 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
    +      'muted' => [
    +        '#title' => $this->t('Muted'),
    +        '#type' => 'checkbox',
    +        '#default_value' => $this->getSetting('muted'),
    +      ],
    

    muted 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.

  2. +++ b/core/modules/file/src/Plugin/Field/FieldFormatter/FileMediaFormatterBase.php
    @@ -56,6 +58,16 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
    +      'playsinline' => [
    +        '#title' => $this->t('Plays Inline'),
    +        '#type' => 'checkbox',
    +        '#default_value' => $this->getSetting('playsinline'),
    +      ],
    

    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.

  3. As we're adding new defaults we need an update function to update existing configuration
aleevas’s picture

StatusFileSize
new3.86 KB
new5.69 KB

@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!

alexpott’s picture

+++ b/core/modules/file/config/schema/file.schema.yml
@@ -86,7 +86,9 @@ file.formatter.media:
       label: 'Display of multiple files'
-
+    playsinline:
+      type: boolean
+      label: 'Plays inline'
 field.formatter.settings.file_audio:

Let'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.

alexpott’s picture

+++ b/core/modules/file/config/schema/file.schema.yml
@@ -86,7 +86,9 @@ file.formatter.media:
     multiple_file_display_type:
       type: string
       label: 'Display of multiple files'
-
+    playsinline:
+      type: boolean
+      label: 'Plays inline'

Actually now playsinline is not part of the base class this change is not necessary.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

hchonov’s picture

Status: Needs work » Needs review
StatusFileSize
new823 bytes
new3.87 KB

Fixing the attribute prepartion for playsinline.

ranjith_kumar_k_u’s picture

StatusFileSize
new4.15 KB
new217 bytes

Fixed Cspell issue

mrshowerman’s picture

Since there's #3090641: Add 'muted' configuration to audio field formatter. for the muted part, shouldn't we reduce the scope of this issue and concentrate just on the playsinline attribute?

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

rinku jacob 13’s picture

StatusFileSize
new61.3 KB
new61.23 KB

I 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

rinku jacob 13’s picture

StatusFileSize
new60.19 KB
yashingole’s picture

Assigned: Unassigned » yashingole
yashingole’s picture

Assigned: yashingole » Unassigned
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new70.06 KB
new67.92 KB

Verified 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

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 28: 3046152-28.patch, failed testing. View results

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

martijn de wit’s picture

Status: Needs work » Reviewed & tested by the community

back to RTbC. Patch in D 10.1.x is green

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 28: 3046152-28.patch, failed testing. View results

rpayanm’s picture

Status: Needs work » Reviewed & tested by the community

Random test failure.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 28: 3046152-28.patch, failed testing. View results

martijn de wit’s picture

Status: Needs work » Reviewed & tested by the community
lubwn’s picture

Applying 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.

catch’s picture

Component: file system » file.module
Status: Reviewed & tested by the community » Needs work

This 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.

agoradesign’s picture

@catch muted is already configurable in the video formatter. I guess, it wasn't, when the issue was created

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

bvoynick’s picture

Title: Video media needs playsinline & muted options » Video media needs playsinline option
Issue summary: View changes

Updated issue title and summary

kostyashupenko’s picture

Status: Needs work » Needs review

Muted 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

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs upgrade path

Looking at #28 noticed we will need an upgrade path + tests for the upgrade because of the schema changes.

rajab natshah’s picture

StatusFileSize
new4.11 KB

Drupal 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

ahmad abbad’s picture

Patch #49 worked for me
Drupal 10.2.1

rajab natshah’s picture

Title: Video media needs playsinline option » Add playsinline option to Video media file formatter

rajab natshah’s picture

Attached a static patch file for Drupal core 2024-06-20 10.3.x branch MR 8471, to use with composer patches

yeebot’s picture

Patch #54 works for me on Drupal 10.3.6.

kim.pepper made their first commit to this issue’s fork.

kim.pepper’s picture

Status: Needs work » Needs review
Issue tags: -Needs upgrade path

Added a post update hook and an entity presave as per #43.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The 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.

kim.pepper’s picture

Status: Needs work » Needs review

Changed the post update hook to actually update the field formatter settings.

kim.pepper changed the visibility of the branch 3046152-10-3-x to hidden.

kim.pepper changed the visibility of the branch 3046152-video-media-needs to hidden.

kim.pepper’s picture

Tests are green ✅ Ready for reviews

kim.pepper’s picture

Issue summary: View changes

Updated IS

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

Small comment around upgrade path tests.

kim.pepper’s picture

Status: Needs work » Needs review

Added upgrade test

smustgrave’s picture

Status: Needs review » Needs work
StatusFileSize
new125.35 KB

All feedback for this one appears to be addressed.

Applied the MR locally

locally

Shouldn't the 2 checkboxes for "Muted" and "Plays inline" be above "Display of multiple files". almost missed them.

oways23’s picture

StatusFileSize
new85.89 KB

Re-roll merge request #8472

mrshowerman’s picture

Status: Needs work » Needs review
Issue tags: +GlobalContributionWeekend2025

Re #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.

oily made their first commit to this issue’s fork.

oily’s picture

Rebased and resolved merge conflict.

oily’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
martijn de wit’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

tests are there. See #65

Agree that moving the checkboxes should be a follow up. Muted is already in core.

martijn de wit’s picture

Issue summary: View changes
StatusFileSize
new71.81 KB
new69.15 KB

Added new images for the issue summary, to make the situation clear what is going to change.

smustgrave’s picture

Still think the form should be correct before merging. So will leave for others.

kim.pepper’s picture

@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.

kim.pepper’s picture

I've rebased this on 11.x. In my view this is ready.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Won't hold it up, just feel the form could use some love. That was the only outstanding thing from me.

alexpott’s picture

Saving issue credit.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed
diff --git a/core/modules/file/tests/fixtures/update/post_update_playsinline-3046152-node-article.yml b/core/modules/file/tests/fixtures/update/post_update_playsinline-3046152-node-article.yml
index 99f1ae397ec..8657e1c7667 100644
--- a/core/modules/file/tests/fixtures/update/post_update_playsinline-3046152-node-article.yml
+++ b/core/modules/file/tests/fixtures/update/post_update_playsinline-3046152-node-article.yml
@@ -1,3 +1,4 @@
+# cspell:ignore autoplay
 uuid: 93ccb838-5462-45ee-862a-988b9bdc6e0f
 langcode: en
 status: true

Fixed 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!

  • alexpott committed 46281c68 on 11.x
    Issue #3046152 by kim.pepper, rajab natshah, aleevas, chris_wearebraid,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

berdir’s picture

This 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.

kim.pepper’s picture

Hmm. 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.

catch’s picture

It'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.

guillaumeg’s picture

Rerolling 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.