It's currently not possible to get the embed URL for an embedded video. You're forced to figure it out by yourself or get a rendered iframe element.

When can this be useful? If you wish to take advantage of Video Embed Field's provider detection but only wish to expose the embed URL for ex the REST module so other external services can render the element for themselves.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kallehauge created an issue. See original summary.

Status: Needs review » Needs work

The last submitted patch, 2: separate_the_provider-2723957-2.patch, failed testing.

The last submitted patch, 2: separate_the_provider-2723957-2.patch, failed testing.

The last submitted patch, 2: separate_the_provider-2723957-2.patch, failed testing.

The last submitted patch, 2: separate_the_provider-2723957-2.patch, failed testing.

Sam152’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +BC break

This is a BC break and I'm not convinced this is worth it.

> You're forced to figure it out by yourself or get a rendered iframe element.

That's not strictly true. A renderable array is returned which has all the components split into their meaningful parts. What's to stop you from calling renderEmbedCode and accessing #url and #query?

kallehauge’s picture

BC break is always something to consider, but the module is still in a RC state, so if this should ever be implemented then rather do it now before the module has a stable release.
And you're correct! It is possible to fetch the url (and query) from the render array. I just feel like it is conceptually wrong to "handpick" the value from a render array and the thumbnail has the getLocalThumbnailUri() method so it would also harmonise/unify the provider a bit as well.

/ Kallehauge
BTW: awesome that the module is "already" in a production ready state. Great job!

Sam152’s picture

Yeah, it's certainly not ideal to fish it out of a render array, but I'm still slightly confused how a URL to something which is designed to live within an iframe is useful by itself? Can you expand on your specific use case a bit more?

kallehauge’s picture

Oi! Totally forgot! My specific case right now has this scenario: I'm looping through several provider classes and would like to expose the embed URL. When I'm looping through them and I take the ['#url'] and ['#query'] from the render array, then I have to unset values like "start" and "rel" for Youtube specifically.
So each provider I wish to support (when expanding the module with other contrib modules) I'll have to unset values or specifically cherrypick one (depends on your philosophy of whitelisting vs blacklisting). But youtube playlists uses the argument "list" while vimeo might use something else, so it's not possible to do this logic generically. The getEmbedUrl() method removes the need for this logic.

Edit to answer your question:
I want to expose the embed URL to an external service that wish to render the iframe element by itself so it can add propperties to the element without the need for JavaScript

Sam152’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Sorry, I should clarify, why do you need this functionality? What feature is it serving? It sounds strange you would need a link to an embed URL, without certain parts of the query string, by itself? How is it useful outside the context of an iframe or at all? Is it possible that you should just be using the original input URL for whatever your purpose is? I can't honestly think of a scenario where the information you are extracting is useful?

Thanks for working on this, but at this stage I think it's a "no" for adding this in. It doesn't make sense as part of the interface. There is a reason the method returns a renderable array and not something more strictly defined like an iframe URL. In some cases embed codes are a snippet of javascript with an accompanying div, in which case the getEmbedUrl method doesn't make sense. I'm also not looking forward to coordinating a BC break across a dozen other tagged 8.x releases and providers which people may have purpose written for their own projects.

While it isn't a tagged stable release, I take the BC pretty seriously at this stage given it's use in a few of the big install profiles and the media ecosystem.

kallehauge’s picture

I respect your decision and thank you very much for your time :)

To answer your question of WHY I need the functionality:
I am in a context of a headless setup where Drupal is the backend. The front-end wish to handle all rendering of elements (including iframes) by itself so I'm creating a Normalizer that will handle the output to fulfil the API requirements the front-end has. I'm then calling the ProviderManager as a service in the Normalizer class to convert a VideoEmbedField value (a random video link) to a Provider so I can fetch the embed-url for the video.
So I'm using the following of the modules for this functionality:

  • FieldType
  • FieldWidget
  • ProviderManager (and indirectly Providers)