Problem/Motivation
I have many blog posts that include video embeds at the top, that I want to appear in the trimmed version. Other types of media (documents, images) do appear within the trimmed post, but video content (both local and remote) just gets skipped over, but text from after the video does show up in the trimmed version.
I would expect that the video(s) would appear in the trimmed / Teaser if the text after appears in it.
Using Drupal 10.2.3 on Apache webserver, PHP 8.2.16.
Steps to reproduce
- Select a content type that has a body filed type "Text (formatted, long, with summary)" and create a new node
- Embed a video near the top of the new node body, remote or local or both.
- Add some text after the video(s) and save.
- Look at the Teaser view -- e.g. in a View or Teaser preview. The video content will have been removed but the text after it may be in the Teaser, depending on how many characters the trimmed limit is set to.
Remote video like this is removed:
<drupal-media data-entity-type="media" data-entity-uuid="c88d434d-9776-4635-80e9-4747746e4336"> </drupal-media>
And local video like this is also removed:
<drupal-media data-entity-type="media" data-entity-uuid="920e4c52-ff87-4607-95e8-c9cd5fdca44b"> </drupal-media>
Oddly, the trimmed HTML includes this wrapper around the missing videos (remote first, then local):
<div>
<div class="field field--name-field-media-oembed-video field--type-string field--label-hidden field--item">
</div>
</div>
<div>
<div class="field field--name-field-media-video-file-1 field--type-file field--label-visually_hidden">
<div class="field--label sr-only">Video file</div>
<div class="field--item">
</div>
</div>
</div>@ressa confirms the issue at https://www.drupal.org/forum/support/post-installation/2024-02-27/choose...
Proposed resolution
Expected behavior: Video media elements that are included in the body should appear in the Teaser / trimmed output, subject to the trimmed length limit.
Comments
Comment #2
cilefen commentedThis occurs in the
text_summaryfunction in the text module. It depends on a format passed to it so I would look at its callers. I haven't done a deep look but this may be the intended behavior rather than a bug, although of course it could be changed. Or, it's a bug.Comment #3
pameeela commentedConfirmed this occurs but interestingly the video remains if you use the Smart trim formatter.
Comment #4
leeksoup commented@pameeela - Somehow I overlooked your post earlier. Is the Smart trim formatter you linked a drop-in replacement for the default one?
Comment #5
pameeela commented@leeksoup yes, it works well and also strips HTML tags when calculating the trimming.
Comment #6
cilefen commentedThere is a clear solution then. Can we close this?
Comment #7
pameeela commentedI guess it could be converted to a feature request for adding support to core, or closed since it's nicely solved in contrib.
Comment #8
pameeela commentedOops, didn't mean to change status.
Comment #9
pameeela commentedComment #10
leeksoup commented@pameeela - thanks.
@cilefen - I will test and check whether the contrib module works for me, and report back.
Comment #11
leeksoup commented@cilefen, @pameeela - Yes, the Smart Trim module works for me and resolves both this issue and the related one to strip tags before counting characters for text trimming.
I agree with making it a feature request. Thanks.
Comment #12
smustgrave commentedBumping once to see if this should be closed?
Comment #13
leeksoup commented@smustgrave - I have a solution for this issue and this page documents it. Even though I still think the core function isn't handling this correctly, I have a great workaround, so it can be closed as far as I'm concerned. Thanks.
Comment #15
smustgrave commentedThanks! Since it was a feature request and been a while I will close out. Am assigning credit though for the discussion