diff -u b/core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php b/core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php --- b/core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php +++ b/core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php @@ -270,13 +270,17 @@ * {@inheritdoc} */ public static function isApplicable(FieldDefinitionInterface $field_definition) { - $applicable = parent::isApplicable($field_definition); - if ($field_definition->getTargetEntityTypeId() !== 'media') { return FALSE; } - $media_type = MediaType::load($field_definition->getTargetBundle()); - return $applicable && $media_type && $media_type->getSource() instanceof OEmbedInterface; + + if (parent::isApplicable($field_definition)) { + $media_type = $field_definition->getTargetBundle(); + if ($media_type) { + return MediaType::load($media_type)->getSource() instanceof OEmbedInterface; + } + } + return FALSE; } } diff -u b/core/modules/media/tests/modules/media_test_oembed/media_test_oembed.module b/core/modules/media/tests/modules/media_test_oembed/media_test_oembed.module --- b/core/modules/media/tests/modules/media_test_oembed/media_test_oembed.module +++ b/core/modules/media/tests/modules/media_test_oembed/media_test_oembed.module @@ -1,5 +1,10 @@ drupalLogin($this->drupalCreateUser(['view media'])); $this->lockHttpClientToFixtures(); } @@ -95,6 +95,23 @@ } /** + * Tests that oEmbed media types' display can be configured correctly. + */ + public function testDisplayConfiguration() { + $account = $this->drupalCreateUser(['administer media display']); + $this->drupalLogin($account); + + $media_type = $this->createMediaType([], 'oembed:video'); + $this->drupalGet('/admin/structure/media/manage/' . $media_type->id() . '/display'); + $assert = $this->assertSession(); + $assert->statusCodeEquals(200); + // Test that the formatter doesn't try to check applicability for fields + // which do not have a specific target bundle. + // @see https://www.drupal.org/project/drupal/issues/2976795. + $assert->pageTextNotContains('Can only flip STRING and INTEGER values!'); + } + + /** * Tests the oEmbed field formatter. * * @param string $url @@ -111,6 +128,9 @@ * @dataProvider providerRender */ public function testRender($url, $resource_url, array $formatter_settings, array $selectors) { + $account = $this->drupalCreateUser(['view media']); + $this->drupalLogin($account); + $media_type = $this->createMediaType([], 'oembed:video'); $source = $media_type->getSource();