Provide hook_oembed_providers_alter()

Created on 21 October 2018, about 6 years ago
Updated 13 September 2023, about 1 year ago

Problem/Motivation

Currently, when https://oembed.com/providers.json is fetched to generate a list of available oEmbed providers, there is no opportunity to alter the list of providers.

This would be useful in scenarios such as 1) Peer Tube and 2) oEmbed providers that may be organization-specific. Peer Tube is a decentralized video platform. The user can search videos across multiple instance of PeerTube with different domain names. Re custom oEmbed providers, the University of Nebraska-Lincoln hosts its own video service, which will soon support oEmbed. This functionality is needed by this organization.

Proposed resolution

Provide hook_oembed_providers_alter(). (Media already provides hook_oembed_resource_url_alter()).

Remaining tasks

  • Subsystem maintainer review

User interface changes

None.

API changes

Adding hook_oembed_providers_alter().

Data model changes

None.

Release notes snippet

TBD

Original report by phjou

I have studied the code from the oEmbed system in the core and I have discovered that it is based on the list provided by https://oembed.com/providers.json

This is a good list to start but I am wondering how to add a provider to this list?
You can host a new file with the additional services and change the settings "oembed_providers_url". But this method is really complicated to just support more providers.

Moreover I am creating this issue in order to support PeerTube which is a decentralized video platform. The user can search videos across multiple instance of PeerTube with different domain names. Such a complicated way to support a new provider is just impossible for a simple contributor.

In order to resolve this problem:
- The user should be able to override the default URL. The issue already exists for another reason: #2999018 β†’
- We should be able to alter the provider list by using a hook. What do you think about adding an alter call in the getAll function from Drupal\media\OEmbed\ProviderRepository?

✨ Feature request
Status

Postponed

Version

11.0 πŸ”₯

Component
MediaΒ  β†’

Last updated about 12 hours ago

Created by

πŸ‡¨πŸ‡¦Canada phjou Vancouver πŸ‡¨πŸ‡¦ πŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

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

  • πŸ‡ΊπŸ‡ΈUnited States Chris Matthews

    Seems as though there are 3 paths that could be taken ...

    1. Won't fix issue and rely on oEmbed Providers, which already includes hook_oembed_providers_alter()
    2. Implement hook_oembed_providers_alter() in Core per the original proposed resolution in the IS
    3. Re-scope this issue to assist oEmbed Providers as Chris Burge detailed in #71 ✨ Provide hook_oembed_providers_alter() Postponed

    What is the will of the council?

  • πŸ‡ΊπŸ‡ΈUnited States Chris Burge

    @Chris Matthews - Thanks for reanimating this issue.

    Re #71, the first part is still an issue, but it probably falls under the "would be nice" category. We could break the current ->getAll() method into two methods. The first [new] method would solely be responsible for fetching (no caching). The second method would be ->getAll(). It would call the first method and then cache the results in key/value before returning the providers list. From a BC standpoint, it would be 100% non-breaking. Then - the oembed_providers module could call the new fetch-only method instead of ->getAll(). Now that I think about it. It would be pretty easy to implement and to add test coverage. This isn't a heavy lift.

    The second part was addressed in #3296300: Add UI to clear provider list from keyvalue β†’ . If hook_oembed_providers_alter() were implemented in core, then I think we would also want to address the caching issue in core - namely how to clear the values cached in key/value if someone doesn't want to wait 7 days. That might be a can of worms not worth opening.

    What about this?

    1. Add a new, fetch-only method to the ProviderRepository class in core.
    2. Keep hook_oembed_providers_alter() in contrib.
  • πŸ‡ΊπŸ‡ΈUnited States Chris Matthews
    1. Add a new, fetch-only method to the ProviderRepository class in core. πŸ’― βœ… πŸ‘
    2. Keep hook_oembed_providers_alter() in contrib. πŸ’― βœ… πŸ‘

    Both make sense to me.

  • πŸ‡ΊπŸ‡ΈUnited States Chris Burge

    I dove into ProviderRepository, and now that I'm in the code, I'm seeing it's going to be a bit more challenging to refactor ->getAll() into two methods. We'd also have to update ProviderRepositoryInterrface, which creates a BC issue. So - on second thought, let's not move forward on that.

    In terms of this issue, I think we're good to change the status to 'Closed (won't fix)'.

Production build 0.71.5 2024