Error thrown if iframe domain is set in Media settings

Created on 2 February 2023, almost 2 years ago
Updated 15 December 2023, 11 months ago

Problem/Motivation

If an iframe domain is set at /admin/config/media/media-settings as recommended, an error is thrown:

nvalidArgumentException: The internal path component 'https://oembed-meric.mo.gov/media/oembed' is invalid. Its path component must have a leading slash, e.g. internal:/foo. in Drupal\Core\Url::fromInternalUri() (line 416 of core/lib/Drupal/Core/Url.php).
Drupal\Core\Url::fromUri('internal:https://oembed-meric.mo.gov/media/oembed?url=https%3A//www.youtube.com/w...') (Line: 120)
media_oembed_control_preprocess_field(Array, 'field', Array)
call_user_func_array('media_oembed_control_preprocess_field', Array) (Line: 287)
Drupal\Core\Theme\ThemeManager->render('field', Array) (Line: 433)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 446)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array) (Line: 479)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 48)
__TwigTemplate_ef2502f7e6c19829ebf272c7f8054b0f->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array) (Line: 55)
twig_render_template('core/modules/media/templates/media.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('media', Array) (Line: 433)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 243)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 174)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 713)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

Configure an iframe domain in the media settings. For example, on our sites, we have both "foo.bar" and "oembed-foo.bar" pointing at the site, with "https://oembed-foo.bar" entered as the iframe domain.

Configure the field display settings to include a Media oEmbed Control option.

Attempt to view an oEmbed media item using those settings.

Proposed resolution

I believe this is just a matter of checking the src string before creating a URL from it, and creating it a bit differently if it's not an internal path. However, my first experiment with this got an oembed "doesn't match any known resource" error. I'll try further.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States wrd-oaitsd

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

Comments & Activities

  • Issue created by @wrd-oaitsd
  • πŸ‡ΊπŸ‡ΈUnited States wrd-oaitsd

    I believe this will do the trick. Added a bit of conditional handling to media_oembed_control_preprocess_field based on whether or not the iframe_domain is set in media.settings.

  • Status changed to Needs review almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States wrd-oaitsd
  • First commit to issue fork.
  • @nickvanboven opened merge request.
  • @nickvanboven opened merge request.
  • πŸ‡³πŸ‡±Netherlands nickvanboven

    I have created 2 merge request, to always use the patch supplied here, We also had isseus when using multilanguage with custom domains.

  • Status changed to Needs work 11 months ago
  • πŸ‡¦πŸ‡ΊAustralia imclean Tasmania

    Merge requests need to be updated and the changes don't appear to fix the issue.

    Is the patch still valid or is the MR replacing it?

Production build 0.71.5 2024