Vimeo links return the title when getName() is called in drupal/modules/contrib/video_embed_field/src/Plugin/video_embed_field/Provider/Vimeo.php

Would like to add that to YouTube and YouTubePlaylists.

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

cgknutt created an issue. See original summary.

cgknutt’s picture

john franklin’s picture

This is good, but can it be cached so we don't have to hit YouTube's servers every time we render the page?

john franklin’s picture

Status: Active » Needs work

When fetching data via HTTP, modules should be done with Guzzle. See #3062387: Do not use file_get_contents() do download stuff. Use Drupal's http client (Guzzle) to do that, for better error handling for an example patch.

john franklin’s picture

Status: Needs work » Needs review
StatusFileSize
new4.01 KB

Updated patch and some other cleanup.

john franklin’s picture

StatusFileSize
new6.48 KB

Cleaner patch, with coding standard updates and the new member function in the test mock object.

john franklin’s picture

StatusFileSize
new5.5 KB

Another run.

Status: Needs review » Needs work
arturs.v’s picture

There is related effort happening here as well: https://www.drupal.org/project/video_embed_field/issues/3253820

Attached a patch that sets iframe title attribute with the help of the new methods.

shelane’s picture

Status: Needs work » Needs review

The updated patch needs review.

robloach’s picture

Title: YouTube - getName() oEmbed and returns title. » Add "title" attribute to YouTube, Vimeo, and Playlist embeds
Status: Needs review » Reviewed & tested by the community
Issue tags: +Accessibility
StatusFileSize
new6.25 KB

The updated patch builds upon the above to add the title to both Vimeo and YouTube Playlists too.

sokru’s picture

Version: 8.x-2.4 » 8.x-2.x-dev
Category: Feature request » Task
Priority: Minor » Normal
Status: Reviewed & tested by the community » Needs review
Related issues: +#2913598: Accessibility enhancements for html output of iframe tag (title, id, name, inner A link)
StatusFileSize
new5.16 KB

Based on patch from #11, but I made few small improvements:
1. No new translation strings, since there's almost 80k installations and some/many of them might have made translations.
2. Removed unrelated coding standard fixes, so its easier to review and get committed.
3. Corrected the return type of oEmbedData()

Added the related issue #2913598: Accessibility enhancements for html output of iframe tag (title, id, name, inner A link). Patch on issue has some related/duplicate code, but it has two interesting features that might be left for follow-up:
- Transliterates and removes some unwanted characters from the title.
- Adds $instace_id argument to renderEmbedCode, so title's will be unique if there's multiple instances of same video on page.

sokru’s picture

StatusFileSize
new5.36 KB
new831 bytes

And caching the response.

sokru’s picture

StatusFileSize
new10.84 KB
new5.85 KB

Added the tests and removed single undefined function (filterCharaters()) from patch on #13.

sokru’s picture

StatusFileSize
new18.12 KB
new7 KB

This fixes the tests other than ProviderUrlParseTest. That would need updating mocks. I'm willing to do that, if that increases the changes of commit.

robloach’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the fixes +1

sokru’s picture

-

sokru’s picture

StatusFileSize
new18.23 KB
new564 bytes

And small improvement by handling the cases if returned json is not valid.

shivansunfire’s picture

Status: Reviewed & tested by the community » Needs review
dydave’s picture

Watchout: #11 is the last patch supported on PHP:7.4.

All the more recent patches contributed afterwards (#12 to #18) use the null safe operator (?->) which is supported from PHP 8 onwards, therefore crashes on PHP 7.4, with the following error:

The website encountered an unexpected error. Please try again later.
ParseError: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in Composer\Autoload\{closure}() (line 110 of modules/contrib/video_embed_field/src/Plugin/video_embed_field/Provider/YouTube.php).

It would be great if we could get a more recent version of the patch compatible with 7.4, but that's not necessarily a priority,

Otherwise, patch from #18 works great on PHP 8.1.

Thanks again to everyone for the great help with this ticket and contributions.

sokru’s picture

StatusFileSize
new18.23 KB
new527 bytes

Small change to decrease severity of logging. This could be debated, but the reasoning is that it will produce noise to logs (eg. when forwarding only emergency/critical/error messages to log service) everytime private video is rendered on cold caches.

herved’s picture

StatusFileSize
new18.28 KB
new4.35 KB
+++ b/src/ProviderPluginBase.php
@@ -103,6 +103,42 @@ abstract class ProviderPluginBase extends PluginBase implements ProviderPluginIn
+        $data = json_decode($body);

I think it would be best to use \Drupal\Component\Serialization\Json::decode

+++ b/src/Plugin/video_embed_field/Provider/Vimeo.php
@@ -48,11 +49,12 @@ class Vimeo extends ProviderPluginBase {
+    $url = sprintf("https://vimeo.com/api/oembed.json?url=%s", $this->getInput());

Shouldn't we use Url::fromUri(...)->toString(), so the url parameter is properly encoded?

herved’s picture

StatusFileSize
new18.88 KB
new4.35 KB

Whoops, discard patch #22, I forgot point 2.
This implements both points.

herved’s picture

StatusFileSize
new5.19 KB

wrong interdiff in #23...

herved’s picture

StatusFileSize
new19.06 KB
new5.37 KB

I forgot to update Vimeo::getRemoteThumbnailUrl... This should work.
It also addresses #20 I believe (PHP 7.4 compatibility) but I have not tested that to confirm.
Attaching new interdiff, still from 21.

herved’s picture

StatusFileSize
new19.71 KB
new15.94 KB

I have 2 more suggestions:

1. Normalize URLs before requesting the oembed endpoint
Most providers accept multiple URL patterns, but this isn't necessarily true when requesting the oembed data.
I noticed that many providers only accept some URL patterns when passed to the oembed endpoint.
And unlike core's Media oembed, video_embed_field doesn't validate that the given URL returns oembed data, before saving/storing data.
It is relevant for getting Youtube playlist title, e.g:
- Raw URL (we get the video title): https://www.youtube.com/oembed?url=https%3A%2F%2Fwww.youtube.com%2Fwatch...
- Normalized (we get the playlist title): https://www.youtube.com/oembed?url=https%3A%2F%2Fwww.youtube.com%2Fplayl...

Also, normalizing would also prevent unnecessary calls to the endpoint for minor/irrelevant URL changes (e.g. http/https, www/non-www, query strings changing, etc).
This is especially relevant when combined with other patches accepting more patterns, such as #3060201: Youtube Privacy Enhanced Mode (using -nocookie.com) (8.x-1.x).
I have added some more test cases.

2. Small change to title format
What about normalizing the titles to "@provider | @title" instead of "@provider Video (@title)".
The video title often contains parentheses, and some providers are not necessarily videos.

james.williams made their first commit to this issue’s fork.

james.williams’s picture

I've spun up a merge request for the most recent patch. However, I'm no fan of the title format, especially as it is forced even when no title could be retrieved from the oembed data - which can make it look something like 'YouTube | tgeXmUkMB9I'. Perhaps the title could be made configurable and/or skipped over if it wasn't retrieved from the oembed data?

james.williams’s picture

OK - see my last commit; the format of the title is now configurable (which avoids adding a new translatable string too), and there's a configuration option to avoid falling back to using the video ID. So by default, titles will come out using that '@provider | @title' format, but those of us who might want something else can configure that to '@title' and untick the box to use a fallback at all.

james.williams’s picture

Tests are finally passing via phpunit :)

mably’s picture

Could we have an MR against the 3.0.x-dev branch?

As it is still in alpha version, we could merge it without taking too many risks.

james.williams’s picture

Thanks! But I see from #3483205-5: Drupal 11 compatibility fixes for Video Embed Field that the video_embed_wysiwyg module has gone from the 3.0.x branch. Which direction would you like to head in?

1. Merge this MR for 8.x-2.x, with a view to merging 8.x-2.x into 3.0.x later (alongside other improvements currently in 8.x-2.x but not 3.0.x)
2. Postpone further work on this issue until video_embed_wysiwyg for 3.0.x is ready (😢 my least favourite option, personally!)
3. Make a version of the current MR from this issue which doesn't include the work for video_embed_wysiwyg, for merging into 3.0.x (and perhaps split out a follow-up for this issue's work for a later 3.0.x version of video_embed_wysiwyg)

I guess it depends on where plans for video_embed_wysiwyg, and your support for 8.x-2.x, are at. If video_embed_wysiwyg isn't going to make a return, we may as well just do option 3. Though you still have plenty of us using 8.x-2.x who might like this functionality in that branch too please!

mably’s picture

Option 3 looks like a good start for me.

james.williams’s picture

Ah I see some of the Vimeo videos used in tests were updated, so I've had to update the expected values too. And it appears that Vimeo only provides limited functionality for channels in the EU now (see https://www.reddit.com/r/vimeo/comments/1gga3gf/comment/luqd62h/), so I've removed the test for that as it fails in the GitLab pipeline.

MR !67 is now ready for 3.0x, with tests passing :)

mably’s picture

Thanks for your great merge-request @james.williams!

Looks like some phpcs and phpstan warnings are still remaining.

And to avoid any BC breaking changes, could we try to make all the new method parameters optional if possible?

james.williams’s picture

OK, all done, and the checks are now fully passing :)

mably’s picture

Thanks!

Let's merge it and see if things break 😉 🤞

mably’s picture

Status: Needs review » Needs work

@james.williams looks like a rebase is needed.

james.williams’s picture

Status: Needs work » Needs review

mably’s picture

Merged. Thanks @james.williams!

mably’s picture

@james.williams what is probably missing is a little update to the README file.

Users will appreciate a bit of documentation about that important new a11y feature.

james.williams’s picture

I don't see any readme file in the 3.0.x branch (or even the 8.x-2.x branch). It feels a bit beyond the scope of this ticket to start one?

mably’s picture

Will try to initialize something.

mably’s picture

james.williams’s picture

That regex didn't change in this ticket's work, and I don't see where this work might have called it more, so I'm not sure that is related?

mably’s picture

That's not about the regexp but the now broken video_embed_echo360 module which seems to override the renderEmbedCode method.

Not sure there is a way to fix that though. But potentially a lot of module inheriting ProviderPluginInterface::renderEmbedCode are probably broken now and will need an update.

We are on an alpha version of a new major version so we are expecting things to break.

But let's try to keep it as low as possible.

james.williams’s picture

Makes sense. Shall we solve any further issues in a follow-up and close this one off now?

mably’s picture

Status: Needs review » Fixed

Let's close it, I don't think we will backport this on 2.x branch.

mably’s picture

Version: 8.x-2.x-dev » 3.0.x-dev

Status: Fixed » Closed (fixed)

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

chrissnyder’s picture

> I don't think we will backport this on 2.x branch.

A backport to the 2.x branch would be welcome. Should I open a new ticket to patch the 2.x branch or add a patch to this issue for 2.x?

mably’s picture

@chrissnyder MR 42 is probably what you are looking for.