Problem/Motivation

#2831944: Implement media source plugin for remote video via oEmbed added media/templates/media-oembed-frame.html.twig

Should've been media-oembed-iframe.html.twig

Causes a fatal when using a theme that doesn't inherit from stable - hence critical since this can happen just using the UI.

Proposed resolution

Rename the template.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

catch created an issue. See original summary.

marcoscano’s picture

Status: Active » Needs review
Issue tags: +Media Initiative
StatusFileSize
new293 bytes

Here is a patch just with the renaming.

Should we add a test for this as well, or it's not worth on this kind of obvious typo?

seanb’s picture

StatusFileSize
new1.11 KB
new1.4 KB

Looks good to me. Tested it with the stark theme. Also added a test for this.

The last submitted patch, 3: 2982307-3-test-only.patch, failed testing. View results

catch’s picture

Is the drupal_flush_all_caches() necessary?

seanb’s picture

Yes, the test does not fail without clearing the cache. Which makes sense since it will use the cached result for the page otherwise.

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

Excellent. Thank you.

phenaproxima’s picture

Title: Misnamed template in media » Misnamed template can cause fatal error in themes that do not extend Stable
phenaproxima’s picture

Status: Reviewed & tested by the community » Needs review

Showed this to @alexpott in Slack and he wondered if there is any way we can have the test do something a little less heavy-handed than flushing call caches. Maybe just clearing the render cache will do the trick here?

alexpott’s picture

Status: Needs review » Needs work
+++ b/core/modules/media/tests/src/FunctionalJavascript/MediaSourceOEmbedVideoTest.php
@@ -136,6 +136,13 @@ public function testMediaOEmbedVideoSource() {
+    drupal_flush_all_caches();

So the test passes without this so we need to have asserts that would cause the test to fail. I.e some asserts either side of this that can determine which template was used. Also let's call $this->resetAll(); so the test container is correctly updated.

catch’s picture

The way I came across this was a php error/warning building the theme registry iirc.

seanb’s picture

Status: Needs work » Needs review
StatusFileSize
new1.36 KB
new1.64 KB
new1.07 KB

In the end it was the cached http response that we should clear. Changed the patch to just invalidate that.

The last submitted patch, 12: 2982307-12-test-only.patch, failed testing. View results

chr.fritsch’s picture

Status: Needs review » Reviewed & tested by the community

This looks good to me.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/media/tests/src/FunctionalJavascript/MediaSourceOEmbedVideoTest.php
@@ -2,6 +2,7 @@
 use Drupal\media_test_oembed\Controller\ResourceController;

@@ -136,6 +137,13 @@ public function testMediaOEmbedVideoSource() {
+    Cache::invalidateTags(['http_response']);

This points to an bigger issue. Patch incoming.

alexpott’s picture

Status: Needs work » Needs review
Issue tags: -Novice
StatusFileSize
new4.59 KB
new2.47 KB
new4.97 KB

The iframe response should have the rendered cache tag because it is something produced by the render system but because it is a special response it's not feed through \Drupal\Core\Render\MainContent\HtmlRenderer::renderResponse() so it doesn't get this cache tag. If it did then \Drupal\system\EventSubscriber\ConfigCacheTag::onSave() would clear it automatically for us. So we need to change \Drupal\media\Controller\OEmbedIframeController to add this cache tag. Looking at that code it is apparent that we need to merge the final render array with the response cache data so we get anything added by the render system. Also this allows us to add the missing cache tags.

Also I've improved the test to actually assert on which templates are being used by turning on twig debug. This means the test fails even if the file is correctly named but the cache tag is not added by OEmbedIframeController.

The last submitted patch, 16: 2982307-16.test-only.patch, failed testing. View results

seanb’s picture

Looks good to me! Probably need someone else to RTBC though.

chr.fritsch’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/media/tests/src/FunctionalJavascript/MediaSourceOEmbedVideoTest.php
@@ -30,6 +31,18 @@ protected function setUp() {
+    // Enable twig debugging to make testing template usage easy.
+    $parameters = $container->getParameter('twig.config');
+    $parameters['debug'] = TRUE;
+    $this->setContainerParameter('twig.config', $parameters);

@@ -135,6 +148,16 @@ public function testMediaOEmbedVideoSource() {
+    $this->assertRaw('core/themes/stable/templates/content/media-oembed-iframe.html.twig');
+    $this->assertNoRaw('core/modules/media/templates/media-oembed-iframe.html.twig');

This is pretty neat. I like it

Patch looks good to me.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 2dc41c8 and pushed to 8.6.x. Thanks!

  • catch committed 2dc41c8 on 8.6.x
    Issue #2982307 by seanB, alexpott, marcoscano: Misnamed template can...

Status: Fixed » Closed (fixed)

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