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.
- 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
-
Comment | File | Size | Author |
---|
Issue fork drupal-2954834
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
marcoscanoIf 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.
Comment #3
bailleux CreditAttribution: bailleux commentedHey 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
Comment #4
seanBThe
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: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.
Comment #5
bailleux CreditAttribution: bailleux commentedHey 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!
Comment #6
dnebrich CreditAttribution: dnebrich commentedI 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.
Comment #9
lamp5Hi @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.
Comment #11
OCTOGONE.dev CreditAttribution: OCTOGONE.dev commented@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.
Comment #12
lamp5Try this module
Comment #15
joel_osc CreditAttribution: joel_osc at OpenPlus commentedHere 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:
Comment #16
joel_osc CreditAttribution: joel_osc at OpenPlus commentedComment #17
BerdirWe 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.
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.
this should only be added if not empty.
$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.
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'] = ...
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.
Comment #18
joel_osc CreditAttribution: joel_osc at OpenPlus commented@berdir thank-you very much for the review, I will make the appropriate changes and re-roll. Cheers!
Comment #19
dhirendra.mishra CreditAttribution: dhirendra.mishra at Valuebound for Valuebound commentedI have worked on few points from #17 comment like point 1,3,4,5.
Hopefully it wud be helpful for u
Comment #20
joel_osc CreditAttribution: joel_osc at OpenPlus commentedThank-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!
Comment #21
joel_osc CreditAttribution: joel_osc at OpenPlus commentedComment #22
BS Pavan CreditAttribution: BS Pavan at Srijan | A Material+ Company commentedFixing test case failure
Comment #23
BS Pavan CreditAttribution: BS Pavan at Srijan | A Material+ Company commentedFixing test case failure, adding srclang to dictionary.txt file
Comment #25
joel_osc CreditAttribution: joel_osc at OpenPlus commentedThank-you @BS Pavan for your help!
Comment #26
BS Pavan CreditAttribution: BS Pavan at Srijan | A Material+ Company commentedFixed failing test cases of SchemaIncompleteException.
Comment #27
catchManually 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.
Comment #28
Berdir> 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.
Comment #29
catchI 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.
Comment #30
demonde CreditAttribution: demonde commented#26 works for me. It would be nice if you could select an image style.
Comment #32
Mistrae CreditAttribution: Mistrae commentedPatch updated for 9.3
Comment #34
sleitner CreditAttribution: sleitner commentedAdds test and fixes label handling in formatter without language module enabled:
Comment #35
sleitner CreditAttribution: sleitner commentedComment #36
sleitner CreditAttribution: sleitner commentedComment #37
sleitner CreditAttribution: sleitner commentedPlease review. Adds test and fixes label handling in formatter without language module enabled:
Comment #38
sleitner CreditAttribution: sleitner commentedComment #39
maddentim CreditAttribution: maddentim commentedPatch #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.
Comment #40
mrshowerman@maddentim, see #3046152: Video media needs playsinline option for the
playsinline
attribute.Comment #41
amin.ankitI'll review this patch.
Thanks.
Comment #42
amin.ankitComment #44
sleitner CreditAttribution: sleitner commentedComment #45
pbouchereau CreditAttribution: pbouchereau as a volunteer commentedRerolled patch.
Comment #46
pbouchereau CreditAttribution: pbouchereau as a volunteer commentedRerolled patch with git format.
Comment #47
sleitner CreditAttribution: sleitner commented@pbouchereau the patch needs to be based in the docroot, not within core
Comment #48
pbouchereau CreditAttribution: pbouchereau as a volunteer commented@sleitner
And without a missing file too... learning the hard way.
Thanks.
Comment #50
sleitner CreditAttribution: sleitner commentedphpunit 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.
Comment #51
sleitner CreditAttribution: sleitner commentedComment #53
sleitner CreditAttribution: sleitner commentedBranch testing only failed temporarily.
Comment #55
sleitner CreditAttribution: sleitner commentedBranch testing only failed temporarily again.
Comment #56
Martijn de Witupdated 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
Comment #57
Martijn de Witmaking clear the current patch is about mapping the fields at a media entity.
Comment #59
sleitner CreditAttribution: sleitner commentedBranch testing only failed temporarily again.
Comment #61
sleitner CreditAttribution: sleitner commentedBranch testing only failed temporarily again.
Comment #62
catchThe 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.
Comment #63
Martijn de WitWe 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)
Comment #64
AnybodyAs 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.
Comment #66
AnybodyYay, 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 intoprepareAttributes()
or what's the reason for the decision to put it intoviewElements()
.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.
Comment #67
AnybodyCurrent status:
Comment #68
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedComment #69
Anybody@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...
Comment #70
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedI added a few comments, otherwise LGTM!
Comment #71
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedForgot to mention it. I debugged the cache tags and they also LGTM!
Comment #72
AnybodyThanks @Grevil, I fixed the image style test now, please review finally.
Comment #74
AnybodySwitching back to 10.1.x so we hopefully get this in before stable as minor fix.
Comment #75
catchSee 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.
Comment #76
AnybodyThanks @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.
Comment #77
Martijn de WitTesting the new image style feature.
A user hasI have now 3 options within the poster field: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?Comment #78
AnybodyThank you for the feedback @Martijn de Wit. This shows possible confusion for end-users.
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?
Comment #80
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedAdded 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.
Comment #81
Martijn de WitA 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 :)
Comment #82
smustgrave CreditAttribution: smustgrave at Mobomo commentedTook a look and believe we will need an upgrade path for the new formatter settings.
Comment #83
AnybodyThanks @smustgrave! That would mean, we need an update path to set all values to empty on existing formatters:
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?
Comment #84
smustgrave CreditAttribution: smustgrave at Mobomo commentedMay be a good example https://www.drupal.org/project/drupal/issues/3309016
Comment #85
catchYes 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.
Comment #87
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedI 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!
Comment #88
smustgrave CreditAttribution: smustgrave at Mobomo commentedMay be worth asking #contribute channel.
But the version number wouldd be 101021
Comment #89
catchThe 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.
Comment #90
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedThank 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?
Comment #91
catchFor an example of another update, see:
Which is related to:
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/trackSo... 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.
Comment #92
catchTagging for needs subsystem maintainer review to hopefully get a second opinion on that last bit.
Comment #93
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedThanks for the clear-up @catch! I'll have a look again, once everything is discussed with the relevant sub system maintainer! :)
Comment #94
catchI 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.Comment #95
Anybody@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.
Comment #96
seanBSince 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 thekind
attribute properly. It would already help a lot to configure thekind
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.Comment #97
catchI 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).
Comment #98
seanBI 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 singlekind
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 multiplekind
attributes, I think we need to be able to configure a different file field for eachkind
. This is a bit more complex, but if we need to support this I would probably vote to do it like this.Comment #99
AnybodyThanks 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
and transcriptto HTML5 media videos"poster image andtranscript to HTML5 media videos" as follow-up and postpone it on this oneWould have been better we did this earlier, sorry.
Comment #100
catchYes 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.Comment #101
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedComment #102
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedCreated the child issue here: #3372592: Add track to HTML5 media videos.
Comment #103
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedAlright, 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.
Comment #104
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer 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 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 #106
kostyashupenkoRebased
Comment #107
smustgrave CreditAttribution: smustgrave at Mobomo commentedSeems we are missing upgrade test coverage. Should be simple though to add.
Comment #108
shree.yesare CreditAttribution: shree.yesare at Acquia commentedUpdated the patch from #48 to include media entity reference field for thumbnail image on Drupal 10.x
Comment #109
shree.yesare CreditAttribution: shree.yesare at Acquia commentedUpdated the patch from #48 to display default image from selected poster image field, if no thumbnail is added to video media.
Comment #110
shree.yesare CreditAttribution: shree.yesare at Acquia commentedUpdating the patch in #109
Fix issue if no default image is added to field.
Comment #111
Martijn de WitWhy 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...
Comment #112
Priya gupta CreditAttribution: Priya gupta at Cognizant Technology Solutions commentedThis 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
Comment #113
Martijn de WitResolved merge conflicts after #3420980: Convert FieldFormatter plugin discovery to attributes was committed.
Comment #114
Martijn de WitComment #115
Martijn de WitHiding all old patches
@todo: