Problem/Motivation & Steps to reproduce

Drupal core comes with several Media entities; audio, file, image, external video and local video.

When a content editor uses the local video entity, it only allows you to upload the video. There is no default option to include a poster image.

Proposed resolution

Extend the possibility to map fields on a media entity.

  1. a mapping field for the poster

Remaining tasks

Now, the idea is to offer the possibility to display a poster image using content from the field_local_image_file for the HTML5 video.

It would be nice if this feature could be managed by {{ attributes }} but I cannot figure how to implement this.

Thank you!

Gilles

User interface changes

1 extra mapping field at the local video media entity

API changes

-

Data model changes

-

CommentFileSizeAuthor
#112 2954834-112.patch7.54 KBPriya gupta
#110 2954834-110.patch12.26 KBshree.yesare
#109 2954834-109.patch12.2 KBshree.yesare
#108 2954834-Image-Media-reference-field.png111.25 KBshree.yesare
#108 2954834-108.patch18.04 KBshree.yesare
#104 2954834-nr-bot.txt90 bytesneeds-review-queue-bot
#77 2954834-poster-field-image.png79.9 KBMartijn de Wit
#77 2954834-poster-field-tumbnail.png82.4 KBMartijn de Wit
#77 2954834-poster-field-none.png61.76 KBMartijn de Wit
#67 video_poster_transcript.png12.36 KBAnybody
#63 video-settings-drupal.png71.83 KBMartijn de Wit
#48 2954834-48.patch11.64 KBpbouchereau
#46 2954834-46.patch7.37 KBpbouchereau
#45 2954834-45.patch12.15 KBpbouchereau
#36 drupal_2954834_36.patch11.59 KBsleitner
#35 drupal_2954834_35.patch11.58 KBsleitner
#34 drupal_2954834_34.patch11.28 KBsleitner
#32 2954834-32.patch7.22 KBMistrae
#26 interdiff-23-26.txt429 bytesBS Pavan
#26 2954834-26.patch8.61 KBBS Pavan
#23 interdiff-20-23.txt5.53 KBBS Pavan
#23 2954834-23.patch8.07 KBBS Pavan
#22 interdiff-20-22.txt5.36 KBBS Pavan
#22 2954834-22.patch7.82 KBBS Pavan
#20 interdiff_15_20.txt4.68 KBjoel_osc
#20 media-video-transcript-poster-2954834-20.patch6.47 KBjoel_osc
#20 attributes_error.png157.24 KBjoel_osc
#19 2954834-19.patch5.59 KBdhirendra.mishra
#19 interdiff_15-19.txt2.33 KBdhirendra.mishra
#15 media_display.png299.24 KBjoel_osc
#15 media_fields.png240.96 KBjoel_osc
#15 media-video-transcript-poster-2954834-15.patch5.54 KBjoel_osc

Issue fork drupal-2954834

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bailleux created an issue. See original summary.

marcoscano’s picture

Category: Feature request » Support request

If the image you want to show as a poster is tied to the video file uploaded, maybe you want to have the image field on the video media type instead? Then you can create a viewmode that shows the image, and other that shows the video, and render the entity using one or another depending on the context.

bailleux’s picture

Hey Marcos,

The custom media type has indeed two fields, one for the image and another one for the video, which allows the creation of a view with thumbnails linking to the corresponding video.

What I cannot achieve in Views is to rewrite results in order to have a structure like this:
<video controls="controls" poster="/path/to/local/media/image.jpg"><source src="/path/to/local/media/video.mp4" type="video/mp4" /></video>

For instance, this does not work:
<video controls="controls" poster="{{ field_media_image }}"><source src="{{ field_media_video }}" type="video/mp4" /></video>

This is the reason why I try to work on the {{ attributes }} of the file-video.html.twig file mentioned above.

Btw, it would be nice if you could forward my question to the Drupal Media Initiative team.

Thank you!

Gilles

seanB’s picture

Version: 8.5.0 » 8.7.x-dev
Component: media system » file system
Category: Support request » Feature request

The FileVideoFormatter is provided by the file module. It would be nice if you can select an image field from the parent entity in the formatter (when the image module is installed). That way you could:

  • Create a media type with a 'Video' source
  • Add a image field to your media type
  • Select the image field as 'poster' on the formatter of the video field
  • Add the poster attribute in the formatter during rendering

Moving this to the file module since this is not a media specific problem. You could want the same functionality using a video file field and image field on a node.

bailleux’s picture

Hey Sean,

Glad you moved this thread to the file module of the 8.7 branch, where it could get more attention from the community. Hopefully, a poster image will be available for any HTML5 video created with the media module when Drupal 8.7 will be stable in March 2019.

In the meantime, I remain at full disposal for testing any other solution implemented via views or a twig file.

Thank you!

dnebrich’s picture

I had the same problem. I may switch back to using video.js module as there's an issue/patch there to support poster with core media.

For now, I modified the twig file. I didn't try the views approach like you did. I added an image field to the media video type that can be optionally uploaded when creating the local video. The image has to have the same name (minus extension) of the video file.

Yea, not ideal to do this logic in twig perhaps, but I just want it to work without having to write code or something else.

{# Get poster from first src #}
{% set file = files|first %}
{% if 'src' in file.source_attributes|keys %}
  {% set parts =  file.source_attributes.src|split('.', -1) %}
  {% set poster = parts|join('.') ~ '.jpg' %}
{% endif %}

{# Add poster to attributes #}
{% if poster is defined %}
  {% set attributes = attributes.setAttribute('poster', poster) %}
{% endif %}

<video {{ attributes }}>
  {% for file in files %}
    <source {{ file.source_attributes }} />
  {% endfor %}
</video>
{{ devel_breakpoint() }}

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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.

lamp5’s picture

Hi @all. I met with this problem on many projects. During implementing a Media thumbnail video module, I added an extended video formater that works with media video and attach media thumbnail image like a html5 video poster attribute. Let's try.

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.

OCTOGONE.dev’s picture

@lamp5
Can you provide more details please?
I need it for my project : i've changed the default video player with mediaelement player and i need video thumbnails. With the mediaelement video player there is a attribute "poster" for the tag = that s the thumbnails of the video.

i want that thumbnails to be generated automaticaly. Drupal 8 does that for the default video player, can i fetch that thumbnails? Or with the field "thumbnails" that i see in the display view of the media content type "video"? Or do i have to generate it with a tool, like a video formater as you say.

lamp5’s picture

Try this module

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.

joel_osc’s picture

Here is patch that adds the ability to specify a field on the media video entity to use as a poster file as well as a field to use as a transcript file. So, in order to add poster and transcript capabilities to your media video file entity you would:

  1. Install this patch
  2. Add an image field for the poster to the media->video_file bundle
  3. Add a file field for the transcript (vtt) to the media->video_file bundle
  4. Under manage display configure one or more display modes to use the two new fields you just created
  5. Create a new video_file with poster and transcript
  6. On a node using Add media add your media entity
  7. Save and view node
joel_osc’s picture

Title: Media module in core: add poster image to HTML5 videos » Media module in core: add poster image and transcript to HTML5 videos
Berdir’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
  1. +++ b/core/modules/file/src/Plugin/Field/FieldFormatter/FileVideoFormatter.php
    @@ -40,6 +46,27 @@ public static function defaultSettings() {
    +    $image_fields = [0 => $this->t('None')];
    

    We support #empty_option on #type select to define that, you don't need to put that in the array. And those empty options usually have '- None -' or so t o separate them from the other values.

  2. +++ b/core/modules/file/src/Plugin/Field/FieldFormatter/FileVideoFormatter.php
    @@ -66,6 +93,18 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
           ],
    +      'poster' => [
    +        '#type' => 'select',
    +        '#title' => $this->t('Poster field'),
    +        '#default_value' => $this->getSetting('poster'),
    +        '#options' => $image_fields,
    +      ],
    +      'transcript' => [
    +        '#type' => 'select',
    +        '#title' => $this->t('Transcript field'),
    +        '#default_value' => $this->getSetting('transcript'),
    +        '#options' => $file_fields,
    

    I'd say we should either hide those options if no candidates are available or include instructions on how to use them, for example as a description that says that a file/image field needs to be created.

  3. +++ b/core/modules/file/src/Plugin/Field/FieldFormatter/FileVideoFormatter.php
    @@ -79,9 +118,46 @@ public function settingsSummary() {
         ]);
    +    $summary[] = $this->t('Poster field: %poster', ['%poster' => $this->getSetting('poster')]);
    +    $summary[] = $this->t('Transcript field: %transcript', ['%transcript' => $this->getSetting('transcript')]);
    

    this should only be added if not empty.

  4. +++ b/core/modules/file/src/Plugin/Field/FieldFormatter/FileVideoFormatter.php
    @@ -79,9 +118,46 @@ public function settingsSummary() {
    +      $file = $entity->get($this->getSetting('poster'))[0];
    +      $file_uri = $file->entity->getFileUri();
    +      $poster = file_url_transform_relative(file_create_url($file_uri));
    +
    

    $file should be $file_item or so, as it is not a $file entity but a FileItem object.

    file_create_url() and file_url_transform_relative() are now deprecated in favor of the new file url generator service in Drupal 9.3

    I'd suggest using $item->entity->createFileUrl() which is an existing wrapper for that.

  5. +++ b/core/modules/file/src/Plugin/Field/FieldFormatter/FileVideoFormatter.php
    @@ -79,9 +118,46 @@ public function settingsSummary() {
    +      $attributes = $elements[0]['#attributes'];
    +      $attributes->setAttribute('poster' , $poster);
    +      $elements[0]['#attributes'] = $attributes;
    

    attributes is an object, you don't need to set a reference to it back, it's also very common to rely on array access with it and just do [#attributes']['poster'] = ...

  6. +++ b/core/modules/file/src/Plugin/Field/FieldFormatter/FileVideoFormatter.php
    @@ -79,9 +118,46 @@ public function settingsSummary() {
    +      $languages = \Drupal::languageManager()->getNativeLanguages();
    +      $elements[0]['#transcript'] = [
    +         'file' => $transcript,
    +         'srclang' => $langcode,
    +         'label' => $languages[$langcode]->label(),
    +      ];
    

    I don't think you can blindly assume that the language of that file is actually going to be $langcode, there might be a translation for it.

    We can't guarantee that this is correct, but it's more likely to work if you check if $entity has a translation for $langcode, and then a) get that translation to get the value from a possibly translated file field in the correct language and if that's not available, us the active language of the entity.

joel_osc’s picture

@berdir thank-you very much for the review, I will make the appropriate changes and re-roll. Cheers!

dhirendra.mishra’s picture

I have worked on few points from #17 comment like point 1,3,4,5.

Hopefully it wud be helpful for u

joel_osc’s picture

Thank-you for the help @dhirendra.mishra! I have addressed all of the comments from @berdir now with the exception of #5 which throws an error if you treat it as an array (see attached with dpm). That being said I think I improved how I added the poster attribute be using the "merge" method. I am not sure I handled the translations correctly for #6, I would appreciate any recommendations there!

joel_osc’s picture

Status: Needs work » Needs review
BS Pavan’s picture

Fixing test case failure

BS Pavan’s picture

Fixing test case failure, adding srclang to dictionary.txt file

Status: Needs review » Needs work

The last submitted patch, 23: 2954834-23.patch, failed testing. View results

joel_osc’s picture

Thank-you @BS Pavan for your help!

BS Pavan’s picture

Status: Needs work » Needs review
FileSize
8.61 KB
429 bytes

Fixed failing test cases of SchemaIncompleteException.

catch’s picture

Title: Media module in core: add poster image and transcript to HTML5 videos » Add poster image and transcript to HTML5 media videos
Component: file system » media system
Issue tags: +Needs issue summary update

Manually tested the poster functionality on a real site (dev only for now), and it's working nicely. Using image/file fields on the media type with configuration seems like a good approach (although also shows that we can't retire those fields entirely in favour of media, since we need them on media entities...).

Still needs automated test coverage, and didn't manually test the transcript yet.

Berdir’s picture

> although also shows that we can't retire those fields entirely in favour of media, since we need them on media entities...

I'm still confused why anyone thinks that's a option :) Image/Document medias were always going to require image/file fields? Media is no replacement, it's a system on top of the existing features. All we can do is explain it better in the UI when you want to use what.

catch’s picture

I think it's more having both media and file/image as options for configurable fields on nodes and similar entities, but yeah not sure how to restrict that either except via docs.

demonde’s picture

#26 works for me. It would be nice if you could select an image style.

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.

Mistrae’s picture

Patch updated for 9.3

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.

sleitner’s picture

Status: Needs review » Needs work
FileSize
11.28 KB

Adds test and fixes label handling in formatter without language module enabled:

$label = ($languages[$langcode] instanceof Language) ? ($languages[$langcode]->getName()) : ($languages[$langcode]->label());
 
sleitner’s picture

sleitner’s picture

sleitner’s picture

Status: Needs work » Needs review

Please review. Adds test and fixes label handling in formatter without language module enabled:

$label = ($languages[$langcode] instanceof Language) ? ($languages[$langcode]->getName()) : ($languages[$langcode]->label());
 
sleitner’s picture

maddentim’s picture

Patch #37 works great for us! Thanks!

Maybe this should be a separate issue, but it would be nice to implement a switch to add the attribute "playsinline". I needed to add that to our to get out hero video to autoplay on iPhones.

mrshowerman’s picture

@maddentim, see #3046152: Video media needs playsinline option for the playsinline attribute.

amin.ankit’s picture

Assigned: Unassigned » amin.ankit

I'll review this patch.

Thanks.

amin.ankit’s picture

Assigned: amin.ankit » Unassigned

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.

sleitner’s picture

pbouchereau’s picture

FileSize
12.15 KB

Rerolled patch.

pbouchereau’s picture

Rerolled patch with git format.

sleitner’s picture

@pbouchereau the patch needs to be based in the docroot, not within core

pbouchereau’s picture

@sleitner
And without a missing file too... learning the hard way.
Thanks.

Status: Needs review » Needs work

The last submitted patch, 48: 2954834-48.patch, failed testing. View results

sleitner’s picture

Status: Needs work » Needs review

phpunit has been updated in DrupalCI to 9.6.1 and throws new deprecation warnings. Not related with your patch as far as I can see.

We should wait for the next 9.5.x branch testing run and rerun the test as soon the problem is solved.

sleitner’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 48: 2954834-48.patch, failed testing. View results

sleitner’s picture

Status: Needs work » Reviewed & tested by the community

Branch testing only failed temporarily.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 48: 2954834-48.patch, failed testing. View results

sleitner’s picture

Status: Needs work » Reviewed & tested by the community

Branch testing only failed temporarily again.

Martijn de Wit’s picture

Issue summary: View changes
Issue tags: +media, +video
Related issues: +#3046152: Video media needs playsinline option

updated the issue summary.

Wondering if this needs a review / sign off from a 'subsystem' media maintainer. Already seeing some of them commenting.

Added some tags so hopefully it will reach more people, searching the issue queue :)

----

btw really liking this new feature

Martijn de Wit’s picture

Issue summary: View changes

making clear the current patch is about mapping the fields at a media entity.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 48: 2954834-48.patch, failed testing. View results

sleitner’s picture

Status: Needs work » Reviewed & tested by the community

Branch testing only failed temporarily again.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 48: 2954834-48.patch, failed testing. View results

sleitner’s picture

Status: Needs work » Reviewed & tested by the community

Branch testing only failed temporarily again.

catch’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/file/src/Plugin/Field/FieldFormatter/FileVideoFormatter.php
@@ -66,6 +92,22 @@ class FileVideoFormatter extends FileMediaFormatterBase {
+        '#type' => 'select',
+        '#title' => $this->t('Poster field'),
+        '#description' => empty($image_fields) ? $this->t('Please add an image field to this media entity to use the poster feature.') : NULL,
+        '#default_value' => $this->getSetting('poster'),
+        '#options' => $image_fields,

The text here shouldn't use 'Please', I think we have an issue around to remove please from the code base entirely. Also not sure 'poster feature' helps much.

Maybe:

'An image field to use as the source of the poster attribute'?

--

Also what happens if the poster image uploaded is wildly different dimensions to the video - does this need to support image styles? Will add some complexity to the patch to do so, but was also mentioned in #30.

Martijn de Wit’s picture

FileSize
71.83 KB

We have tested this patch for over a month now and I agree with catch. without an image style it is not usable for content-editors.

For site builders the option list is getting really long now and with adding image style options inside this screen I think we need some extra structure like fieldsets/details to group some settings. (also used an other patch to add some other video settings)

video display settings

Anybody’s picture

As we're now running into this requirement, I'll create a MR from the latest patch and will try to work on this. Really helpful addition.

Anybody’s picture

Yay, it basically works!! :)
Give it a try on the tugboat preview.

Now I'm wondering, if the implementation currently in viewElements() shouln't at least partially be moved into prepareAttributes() or what's the reason for the decision to put it into viewElements().
Also I'm not totally sure about the Cache tags implementation.

Would be nice to have another review, I think we're making progress here and I'm happy to learn details. Also we should have a look at the existing tests again, I didn't touch them yet.

Anybody’s picture

FileSize
12.36 KB

Current status: Video transcript poster

Grevil’s picture

Status: Needs work » Needs review
Anybody’s picture

@Grevil please note the 9 upstream test fails in core, that will also fail here, until it's resolved in core.

I guess we have to wait for 10.1.x-dev branch to pass...

Grevil’s picture

Status: Needs review » Needs work

I added a few comments, otherwise LGTM!

Grevil’s picture

Forgot to mention it. I debugged the cache tags and they also LGTM!

Anybody’s picture

Status: Needs work » Needs review

Thanks @Grevil, I fixed the image style test now, please review finally.

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.

Anybody’s picture

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

Switching back to 10.1.x so we hopefully get this in before stable as minor fix.

catch’s picture

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

See https://www.drupal.org/about/core/blog/new-drupal-core-branching-scheme-... (linked in the comment above) 11.x is the target branch for everything now and we backport from there.

Anybody’s picture

Thanks @catch!

GitLab rebase didn't work so let's create a fresh new MR against 11.x instead and leave the 10.1.x one if someone uses / needs it in the meantime? @Grevil could you do that?

So the old MR might still be reviewed in the meantime to speed things up.

Martijn de Wit’s picture

Testing the new image style feature.

A user has I have now 3 options within the poster field:

  • None
  • Thumbnail - image field on my video media entity
  • Image - image field on my video media entity

As showed below the thumbnail option and the image option are equal. With both a user can select an image style. So I was wondering what is the difference?

poster field options

poster field options

poster field options

Anybody’s picture

Thank you for the feedback @Martijn de Wit. This shows possible confusion for end-users.

As showed below the thumbnail option and the image option are equal.

It's not the same. While in the "Poster field" you pick the image field to display as poster.
In the "Poster field image style" field, you select the image style (Imagecache was the name in Drupal 7) to apply on the image.

You say the options are equal - but that's not the case and it doesn't look like this is true on your screenshots?

Perhaps the UX team should have a short look to improve the descriptions or field labels?

Grevil’s picture

Added a new branch "2954834-add-poster-image-transcript-from-fields-11.x" and applied the current "MR !4010 " diff.

@Anybody, as you created the MR, you should (hopefully) be able to close it again. I get a 404 error, when trying to close the old MR.

Martijn de Wit’s picture

A yeah, now I get it :)

I have 2 image fields on my video entity. one named 'image' and one named 'thumbnail' from previous tests.
Sorry for the confusing post.

Then it works as advocated, so it was a good test :)

smustgrave’s picture

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

Took a look and believe we will need an upgrade path for the new formatter settings.

Anybody’s picture

Thanks @smustgrave! That would mean, we need an update path to set all values to empty on existing formatters:

      'poster' => '',
      'poster_image_style' => '',
      'transcript' => '',

Is that really needed? I guess if yes, it's because the keys have to be added?
Do you know any similar example we could use for the update hook?

Would it perhaps make sense to add a helper for such cases to make field (formatter / storage) settings updates more simple (DX)? Similar to: #937442: Field type modules cannot maintain their field schema (field type schema change C(R)UD is needed)

At least to me such things always feel quite hard to do it right, having to copy existing examples etc... we shouldn't open that side topic here, I guess, but perhaps this is a good starting point to proceed the discussion in the linked issue or a new meta issue?

smustgrave’s picture

catch’s picture

Is that really needed?

Yes we need to update existing configuration so that if you update and do a config export, the exported configuration matches how things would look if you'd resaved. If we don't do this, then when you save formatter settings later manually, these keys would be added which gets very inconsistent/confusing.

The pattern is to put the logic for adding the new keys into a presave hook, and then using the actual post update function to just load and re-save configuration. Views (both in 10.1 and 9.5) has the most examples of this, but also a grep for ConfigEntityUpdater will find more.

Grevil’s picture

Status: Needs work » Needs review

I added an update hook, but I couldn't figure out, how to specifically target field instances using the "file_video" formatter. Please review and adjust accordingly!

smustgrave’s picture

Status: Needs review » Needs work

May be worth asking #contribute channel.

But the version number wouldd be 101021

catch’s picture

The update should use hook_post_update_NAME() rather than hook_update_N(), and the logic of actually updating the configuration should happen in hook_entity_presave(), not in the update function itself, so that it also runs when importing default config and similar.

Grevil’s picture

Thank you, @catch!

I got the point on using the hook_post_update_NAME() hook rather than the hook_update_N() hook, but didn't understand the hook_entity_presave() part, as we are basically only updating a few "entity_form_display" setting values and do not change the config itself. So why exactly the "hook_entity_presave" hook? Am I missing something? Is there an example with a similar update in core?

catch’s picture

For an example of another update, see:

/**
 * Implements hook_ENTITY_TYPE_presave() for entity_view_display.
 */
function media_entity_view_display_presave(EntityViewDisplayInterface $view_display): void {
  $config_updater = \Drupal::classResolver(MediaConfigUpdater::class);
  assert($config_updater instanceof MediaConfigUpdater);
  $config_updater->processOembedEagerLoadField($view_display);
}

Which is related to:

media_post_update_oembed_loading_attribute()

Grepping for ConfigEntityUpdater will find more post updates which will usually be tied to a presave hook in the respective module.

Looking at this again, I think we might need to do more with the transcript support though:

HTML allows multiple <track> elements, to support subtitles in different languages as well as captions, see the examples on https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track

So... should we think about supporting a multiple value field for 'track'? But then this would ideally support the 'kind' attribute as well as language etc., it is starting to look like another media type with its own fields at that point though and then a multi-value media field on the video entity.

catch’s picture

Tagging for needs subsystem maintainer review to hopefully get a second opinion on that last bit.

Grevil’s picture

Thanks for the clear-up @catch! I'll have a look again, once everything is discussed with the relevant sub system maintainer! :)

catch’s picture

I think this might be worth splitting into two issues - one for poster image for which I assume there should just be one.

And one for transcript/<track> where there are more possibilities - if we do split, that should probably be the new issue since there'll be more to figure out on there. Might be worth waiting to see what media maintainers say though.

Anybody’s picture

@catch totally agree with #94, thought the same yesterday. And I think the poster image is much more important / widely used. Google Webmaster Tools complains, if it's missing, so we should get that one in soon.

Yes, let's wait for media maintainers feedback.

seanB’s picture

HTML allows multiple
elements, to support subtitles in different languages as well as captions, see the examples on https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track

So... should we think about supporting a multiple value field for 'track'? But then this would ideally support the 'kind' attribute as well as language etc., it is starting to look like another media type with its own fields at that point though and then a multi-value media field on the video entity.

Since media entities are translatable, I don't think we need to support different tracks for different languages. You probably only want the track for the current language (like how you would handle translations for other entities).

The kind attribute seems interesting, although I'm not completely sure if we can properly explain the different use-cases to site editors. I think accessibility experts might have more insights on when / how to use the kind attribute properly. It would already help a lot to configure the kind attribute on the formatter. Site builders can add a field description on the field where editors can upload the .vtt files, to make sure their editors understand what kind of input is expected.

catch’s picture

Since media entities are translatable, I don't think we need to support different tracks for different languages. You probably only want the track for the current language (like how you would handle translations for other entities).

I don't think this is right for subtitles. You can have a video in a single language, with subtitles in 15 languages, and as someone watching the video, you would want those subtitles options to be available via the video player, not by having to view different language versions of the entity. i.e. you can watch an English language film with English, English captions, French, or Arabic subtitles. Even if someone is browsing a site in French, and there is a video that only has English audio, they still might want to choose English subtitles instead of French (i.e. if they're trying to learn English and want to pause and read sometimes when it's hard to hear).

seanB’s picture

I guess you are right we probably need to support multiple subtitle files in each translation, since the source field could technically be different for each translation. So you could have a different video for each language, while still wanting subtitles in multiple languages for each translation.

Then we only need to decide how to deal with the kind attribute. I don't feel I'm the best person to make a decision here. At the moment, I'm thinking it is already helpful to be able to configure a single kind value on the formatter for all the files uploaded in the selected file field. That should also be relatively easy to implement. If we need to support multiple kind attributes, I think we need to be able to configure a different file field for each kind. This is a bit more complex, but if we need to support this I would probably vote to do it like this.

Anybody’s picture

Thanks for the discussion! I think we should split this then to not block the poster image implementation, which Google Search Console complains about. This is the key feature most users need.

Implementing transcript is also helpful, but not that widely used, I think. So I'd suggest

  1. We change the title of this issue to "Add poster image and transcript to HTML5 media videos"
  2. We create a sibling issue: "Add poster image and transcript to HTML5 media videos" as follow-up and postpone it on this one
  3. We split the code so that this can be reviewed and merged and work on the transcript feature can be proceeded in detail later on.

Would have been better we did this earlier, sorry.

catch’s picture

Yes splitting is good, but I think we should use track for the new issue rather than transcript, since that covers the transcript vs. subtitle use-cases and the HTML element is the same for both.

Grevil’s picture

Title: Add poster image and transcript to HTML5 media videos » Add poster image to HTML5 media videos
Grevil’s picture

Issue summary: View changes

Created the child issue here: #3372592: Add track to HTML5 media videos.

Grevil’s picture

Status: Needs work » Needs review

Alright, I removed all the transcript parts. Please review, in case I missed anything!

Also, do we still need to implement the hook_ENTITY_TYPE_presave(), as discussed in #90 and #91? Still unsure about that bit.

EDIT: Not a well describing commit message, my apologies.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
FileSize
90 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 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.

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

kostyashupenko’s picture

Status: Needs work » Needs review

Rebased

smustgrave’s picture

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

Seems we are missing upgrade test coverage. Should be simple though to add.

shree.yesare’s picture

Updated the patch from #48 to include media entity reference field for thumbnail image on Drupal 10.x

shree.yesare’s picture

FileSize
12.2 KB

Updated the patch from #48 to display default image from selected poster image field, if no thumbnail is added to video media.

shree.yesare’s picture

FileSize
12.26 KB

Updating the patch in #109
Fix issue if no default image is added to field.

Martijn de Wit’s picture

Why using the patch from #48?

There is a merge request that is far more recent? containing solution after several discussions with good points ..

The only thing that are missing in the merge request are tests...

Priya gupta’s picture

FileSize
7.54 KB

This patch only for poster attribute.
1. Once the patch applies, then add existing image field
2. Change the poster option as an image in Manage display in Video Media type

Martijn de Wit’s picture

Resolved merge conflicts after #3420980: Convert FieldFormatter plugin discovery to attributes was committed.

Martijn de Wit’s picture