Problem
In Russia the URL https://oembed.com/providers.json, as well the whole website https://oembed.com/ is blocked by providers by Roskomnadzor.
Media module in 8.6. is have setting media.settings.oembed_providers_url which used to parse available and actual oEmbed providers for Media. e.g. for Remote video media type.
In our case, Drupal can't access this JSON file and Remote video can't be created at all. Drupal throws error and thats it.

If I trying to add Remote Video on Simplytest, with same URL, this works fine as expected.
Solution
The URL of the provider database is already a configuration setting. Let's expose it in the Media module's configuration form (along with good help text and validation) so that site builders can easily use an alternate provider database.
Remaining Tasks
Write a patch, write tests, bikeshed the help text so it's nice and clear, commit.
| Comment | File | Size | Author |
|---|---|---|---|
| #59 | interdiff-2999018-58-59.txt | 3.21 KB | phenaproxima |
| #59 | 2999018-59.patch | 14.49 KB | phenaproxima |
| #58 | interdiff-2999018-56-58.txt | 903 bytes | phenaproxima |
| #58 | 2999018-58.patch | 11.13 KB | phenaproxima |
| #56 | interdiff-2999018-55-56.txt | 1.8 KB | phenaproxima |
Issue fork drupal-2999018
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
andypostComment #3
andypostThe workaround could be contrib module to alter this param but it needs kinda "mirroring" for that file
Comment #4
ivnishI confirm this
Comment #5
lukasss commentedI have this problem!
Comment #6
niklanTemporary solution using custom module. GitLab / GitHub
Comment #7
niklanSry, default selections was used and changed statuses.
Comment #8
chr.fritschThe world is so sad....
So we will expose the config setting in the UI. Until we have that, you can change it by drush:
drush cset media.settings oembed_providers_url https://my-oembed-provider-url.com/providers.jsonComment #9
ndobromirov commentedYou just need a proxy server that's not banned.
Comment #10
phenaproximaRe-tagging, and marking for issue summary update since it seems that we agree to expose the config option in the UI. Let's also re-title this issue while we're at it.
Comment #11
podarokThat's super cool.
It's not an issue, it's a feature and a very good improvement.
And I'm not kidding here
Comment #12
podarokComment #13
andypostThis setting needs UI (as #10) and proper error handling when list of providers is not accessible
Comment #14
phenaproximaComment #15
phenaproximaMarking as a feature request.
Comment #16
phenaproximaComment #17
niklanCreated initial patch to push issue forward.
Comment #18
niklanThis patch with try catch for cases like original issue, when URL is not accessible for some reasons.
Comment #19
andypostNice examples from WP about adding custom providers https://generatewp.com/introducing-oembed-provider-generator/
Another big database of providers https://github.com/itteco/iframely
Surely this list should be configurable
Comment #20
gido commented@wengerk and I are working on addding tests on this feature.
Comment #21
gido commentedHere is the patch with some tests coverage (thanks for wengerk the help and review).
I have to change the request send in the
MediaSettingsForm::validationFormto userequestinstead ofget.getis a magic call which was not mockable.We also had to test the form via a
KernelTestbecause we need to mock thehttpClient(Browser Test was not an option in this case). If you know a better way to achieve this, I'm open to suggestion. Testing Drupal Form with a KernelTest was not that easy because of all the dependencies ^^.Now that there is tests on the proposed changes in #17, let's share some thoughts:
Thanks all for your review & feedback.
Comment #22
wengerkIndeed we try our best but let's discuss our implementation, we maybe could find a better approach.
Comment #23
wengerkComment #25
wengerkAdd the missing
@group mediato the tests ... sorry guysComment #26
wengerkComment #27
phenaproximaLooks real good! Removing the "needs tests" tag, since if there is one thing this patch is not lacking, it's tests!
Nit: This does not need to be its own variable. Let's just use
'#default_value' => $this->config('media.settings')->get('oembed_providers_url').This needs to be rephrased a bit. How about: "Enter the URL from which to fetch information about all available oEmbed providers, including the http:// or https:// prefix. Generally, this should only be changed if the default URL is blocked or otherwise inaccessible."
"Trying" --> "Try"
So here is the thing -- this kind of leaks the abstraction that the media.oembed.provider_repository service provides.
I would prefer if we added a new method to ProviderRepositoryInterface, called setProvidersUrl(), which can change the providers URL (permanently) and validate that it is, in fact, accessible. The implementation would look something like:
This validateForm() method would then set an error if it catches a ProviderException. All of this would keep the provider URL abstraction well-encapsulated in the ProviderRepository class.
The only real disadvantage is that, if we do this, we'll need framework manager review on this issue since we're adding a method to ProviderRepositoryInterface. However, we should be okay in the eyes of the backwards compatibility policy under the 1:1 interface:implementation rule.
This should be assertSame().
Comment #28
niklanDone changes from #27.
I'm not good at english. So comments щbsiously needs to be checked for me :)
Comment #29
niklanSorry, wrong git diff called. The actual patch from #28 is here.
Comment #30
phenaproximaThanks! Feel free to set the issue to "Needs review" when you post a new patch; that way the testbot will run tests automatically :)
Comment #31
phenaproximaNice work! Only a few more points, and then I can review the tests. Also tagging for framework manager review, since we're altering ProviderRepositoryInterface.
Additionally, could you post interdiffs along with the patches? It will make things a lot easier to review :) Instructions are at https://www.drupal.org/documentation/git/interdiff. Thanks!
We no longer need the HTTP client in this form, so let's remove it.
We should remove this. I cannot think of any circumstances under which we do *not* want to validate the given URL. If it's invalid, the entire oEmbed system will flat-out break, so we should never allow people to bypass validation in the UI.
Nit: This line is longer than 80 characters.
"Set" should be "Sets".
The description should begin with "(optional)", and we should mention that it defaults to TRUE.
Comment #33
niklanDone.
Comment #35
wengerkWe'll need framework manager review on this issue since we're adding a method to
ProviderRepositoryInterface.The tests need to be rerolled following all changes from #28 to #33.
Comment #36
wengerkHere is a rewrite of tests to match the changes from #28 to #33.
Let's test it !
Comment #38
ivnishwengerk, can you check tests?
Comment #39
wengerkHere is the new coverage.
Let's try it on testbot.
Short story:
I had to replace the whole
Functional/ProviderRepositoryTestand move it as a KernelTest (Kernel/ProviderRepositoryTest) which allows me to proper mock thehttp_client.It's basically the same tests as previously but using a
Kerneltests instead ofBrowserone.Thanks for your review !
Comment #41
wengerkHere the two last tests should be fixed (
ResourceFetcherTest&UrlResolverTest).Comment #43
wengerkHere a reroll since
MediaSettingsFormhas changed a little bit & make this patch not applicable.I was unable to generate the interdiff between the two patch (41 & 43) if someone can help it's would be a pleasure.
Comment #44
wengerkComment #45
diamondsea[deleted]
Comment #46
alex malkovThanks for the #17 patch. It works great on the d8.6.10.
Comment #48
joelpittetLooks like this doesn't apply any more, tagging for reroll.
Comment #49
kostyashupenkoI can apply #43 patch on 8.7.x and 8.8.x
Comment #50
jds1Applies to 8.7.0-beta2 and I see the setting on /admin/config/media/media-settings. Marking as RTBC!
Comment #51
phenaproximaI'm not 100% sure I feel okay with this going in as-is; kicking back to Needs Review to actually, like, review this from a standpoint of "do the new API additions make sense?"
Comment #52
pavelculacov commentedI have same error if i don't have internet ))) or if not have curl localhost (cURL error 60: SSL certificate problem: unable to get local issuer certificate)
Maybe add posibility add local providers.json?
Comment #53
pavelculacov commentedFor Patch have error "Bad Request"
to solve this add in patch method GET
Comment #54
scuba_flyReview of #43
+1 for using DI
Does this also work for the media library?
We don't need this change. $config_factory was already available. No need to move it down. Or am I missing some consistency issue?
Good comment.
I would otherwise think rewind was not needed.
We are always calling this with validate = TRUE
Do we need the extra $validate variable and if statement?
It's like:
if(TRUE) { // trycatch }Note:
I did not review the tests files.
I tried the patch, but It did not solve my issue. But that was unrelated the oembed_providers_url setting was not filled.
Comment #55
phenaproximaI think we should change the approach here a bit. I know it was originally my idea, but in retrospect, I'd prefer if we didn't add a new method to ProviderRepositoryInterface. I also removed the kernel-level MediaSettingsFormTest (for now) -- that should really be a functional test, I think, rather than a kernel test. Marking this "needs tests" for functional tests of the MediaSettingsForm validation stuff I added here.
Comment #56
phenaproximaStreamlined the ProviderRepositoryTest as well, since I think it was doing more mocking than it needed to :)
Comment #58
phenaproximaI also removed the call to $response->getBody()->rewind() in ProviderRepository. We probably should not do that; it makes the abstraction rather leaky. Besides, StreamInterface::__toString()'s doc comment specifically says that implementations need to rewind, so casting the response body to a string is sufficient.
Comment #59
phenaproximaAdded some functional test coverage of the settings form.
I'm removing the "needs framework manager review" tag, since this no longer has any API changes to the oEmbed system. Just needs subsystem maintainer sign-off.
Comment #62
tim-diels+1 for exposing the oembed url. Not only this is needed for another url but also if for some reason the oembed url is not set (config overwritten, ...).
Using the patch provided in #59 seems like a correct approach and works for me.
Comment #63
phenaproximaComment #64
phenaproximaOh, and this is targeted to 8.8 now :)
Comment #65
seanbIn general, plus one for making this configurable! Minor feedback regarding the latest patch.
Saving the config in validate seems a bit weird to me? This solves the fact we don't need to change the providerRepository, but not sure if this is better.
We have tests for a bunch of cases where changing the URL fails. Could we add an extra case where the URL actually is saved to make sure that works as well?
Comment #66
seanb@phenaproxima just pointed out that #3008119: Provide hook_oembed_providers_alter() is a different solution for the same problem. Since changing the default list is probably not very common, I think the hook might be a better solution. It is a bit more flexible and avoids exposing a setting in the UI that a lot of users might not understand.
My vote would be to close this issue and solve this in #3008119: Provide hook_oembed_providers_alter().
Comment #67
phenaproximaI am, to be honest, okay with either solution. The providers URL is already configurable, and has been since day one; this issue was only exposing the setting in the UI. For sites which have to deal with firewalls and other odd situations, they can set the configuration option with Drush, or in a custom module/installation profile.
So, unless there is some other technical reason to continue, I am tentatively +1 for closing this issue (won't fix) and fixing #3008119: Provide hook_oembed_providers_alter().
Comment #69
chris matthews commentedIn #3008119: Provide hook_oembed_providers_alter() comment #10 @seanB said,
So, closing this issue as a duplicate of #3008119: Provide hook_oembed_providers_alter()
The related change record is here: https://www.drupal.org/node/3097113
Comment #70
chris burge commentedThe requested functionality is now provided by the oEmbed Providers module.