Add support of "preload" attribute into FileMediaFormatterBase

Created on 16 April 2019, over 5 years ago
Updated 6 August 2024, 4 months ago

Problem/Motivation

FileMediaFormatterBase doesn't allow to specifie preload attribute on video and audio file. This attribute allow to control media loading behavior.
(See : https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video)

Proposed resolution

  • Add new "preload" select field into FileMediaFormatterBase with three options :
    • None : The author thinks that the browser should NOT load the video when the page loads,
    • Auto : The author thinks that the browser should load the entire video when the page loads,
    • Metadata : The author thinks that the browser should load only metadata when the page loads.
  • Default value must to be "metadata"

Remaining tasks

  • Create patch to allow this
  • Update tests for FileVideoFormatter and FileAudioFormatter to check preload attribute exist
  • Update schema for the configuration file of the File module

User interface changes

  • New field into configuration form of FileVideoFormatter and FileAudioFormatter
  • Update summary of Fieldformatter

API changes

None

Data model changes

  • update field.formatter.settings.file_video mapping.
✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
File systemΒ  β†’

Last updated about 3 hours ago

Created by

πŸ‡«πŸ‡·France pclaitte Toulouse

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • @pcambra opened merge request.
  • Status changed to Needs review almost 2 years ago
  • πŸ‡ͺπŸ‡ΈSpain pcambra Asturies

    @alexpott I'd love to get this in, I've added @pclaitte changes onto an MR and the following changes:

    - Widget is now radios as suggested
    - Added short descriptions for the 3 options.
    - Added a post update with a config updater

    I think the update needs a test but I'd appreciate some guidance on where to find something similar (this has been my first encounter with the config entity updater)

  • Assigned to pcambra
  • πŸ‡ͺπŸ‡ΈSpain pcambra Asturies
  • Status changed to Needs work almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β†’ as a guide.

    This seems like it's going to need an upgrade path for existing settings.

  • πŸ‡ͺπŸ‡ΈSpain Jose Reyero

    Patch looks good to me, already pretty polished...

    What I'm wondering about is: how "safe" is to force a default preload attribute value on sites that didn't have any?

    I mean, if I had a page full of videos with no 'preload' attribute, maybe just an image placeholder, and suddenly I get that preload=metadata default.... will browsers just start preloading when they didn't before?

    The point is: does it make sense to force a default value? or to force any value at all? Should we skip the update script until the user actually edits the formatter?

    For background, I've found this pretty interesting post about how browsers behave, but note it is 10 years old, couldn't find and updated one... https://www.stevesouders.com/blog/2013/04/12/html5-video-preload/

  • Status changed to Needs review over 1 year ago
  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    See the upgrade path but it needs test coverage. Could be something simple as

    Before this value was null
    Run updates
    This value is now false

    Didn’t test the MR

  • Status changed to Needs review over 1 year ago
  • πŸ‡ͺπŸ‡ΈSpain pcambra Asturies

    @smustgrave please see #35 regarding update path.

  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Yes the update hook is there but there is no test coverage of it.

    See BlockContentUpdateTest for example

  • πŸ‡ͺπŸ‡ΈSpain pcambra Asturies

    @smustgrave the question in #35 refers to whether we should have the update hook in the first place.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    So if I do a config export.
    Go into a field or display using this formatterBase.
    If I make 0 changes but save the field and do drush export again and it's showing this new setting then yes it will need an update path.

    If no then it will not.

    The update hook should set to disabled value though.

    That help some?

  • Status changed to Needs review over 1 year ago
  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    @smustgrave "Should we skip the update script until the user actually edits the formatter?" That's exactly what #35 is explaining.

    It's ok to assume changes can happen when I save the formatter, but NOT when I just upgrade my site. That could have unexpected consequences, and that's what #35 is asking for feedback from @alexpott.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Actually the opposite if I save a formatter without making a change and I get changes in my config now that should not be expected.

    Same for how we handle other field changes but will let alexpott respond.

  • Status changed to Needs work over 1 year ago
  • The Needs Review Queue Bot β†’ tested this issue. It no longer applies to Drupal core. 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.

  • πŸ‡¬πŸ‡§United Kingdom catch

    I only scanned the MR quickly, but I couldn't see the a presave hook to update shipped config (i.e. default config in modules), that should happen as well as the update function.

    We need to update the configuration to something in both post update and presave, so that sites don't get unexpected config changes in runtime - better if they get them during a core update which is when they'll be looking for them.

    So.. I think it comes down to what a non-intrusive update looks like - i.e. should it be 'metadata' or 'none', or do a need an additional option for 'unspecified' to preserve current behaviour and update sites to that?

    Didn't look around for docs on browser behaviour yet so not sure what the answer is, but definitely we should update to something here.

  • First commit to issue fork.
  • πŸ‡©πŸ‡ͺGermany mrshowerman Munich

    Rebased 10.1.x into MR; providing patch for 9.5 in case anyone needs it.
    Leaving in NW as per #45.

  • πŸ‡¬πŸ‡§United Kingdom catch
  • heddn Nicaragua

    πŸ“Œ Add image preload option to help boost actual and perceived performance Needs work is doing some similar things for images. It also has some of the bits around update hooks that are being asked about in #40 and below. For already committed code, look at what ResponsiveImageConfigUpdater is doing.

    Can we update the IS to differentiate between what _this_ issue is doing vs #3309016?

  • πŸ‡©πŸ‡ͺGermany mrshowerman Munich

    mrshowerman β†’ changed the visibility of the branch 11.x to hidden.

  • Issue was unassigned.
  • πŸ‡©πŸ‡ͺGermany mrshowerman Munich

    Created MR against 11.x. Adding patch for 10.3.x.

  • Pipeline finished with Failed
    4 months ago
    Total: 155s
    #245615
  • πŸ‡ΊπŸ‡ΈUnited States wmfinck

    Has this not been implemented? If so, how do I find it? I do not want to apply a patch for something that won't show up in production. But I am sorry for wasting anyone's time if I am missing something...

    I have no preload options at /admin/structure/media/manage/audio/display

    Not being able to prevent preloading of media in D10 is a deal-breaker for me, I cannot use Drupal media. I create sites with audio library pages using views, and when a page of multiple audio files is displayed, sometimes dozens, I cannot have them all downloading.

    For this reason, I am compelled to retain the method I used in Drupal 7, which was to create fields with preconfigured HTML5 code using tokens. Doing that I need a file field and two text fields for every audio file (the easiest way without making a custom module, as I am not a developer).

Production build 0.71.5 2024