Loading core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Media.php +8 −1 Original line number Diff line number Diff line Loading @@ -80,6 +80,13 @@ private function configureViewModes(EditorInterface $editor) { $all_view_modes = $this->entityDisplayRepository->getViewModeOptions('media'); $allowed_view_modes = $media_embed_filter->settings['allowed_view_modes']; $default_view_mode = $media_embed_filter->settings['default_view_mode']; // @todo Remove in https://www.drupal.org/project/drupal/issues/3277049. // This is a workaround until the above issue is fixed to prevent the // editor from crashing because the frontend expects the default view mode // to exist in drupalElementStyles. if (!array_key_exists($default_view_mode, $allowed_view_modes)) { $allowed_view_modes[$default_view_mode] = $default_view_mode; } // Return early since there is no need to configure if there // are less than 2 view modes. if ($allowed_view_modes < 2) { Loading @@ -96,7 +103,7 @@ private function configureViewModes(EditorInterface $editor) { } } // Limit to view modes allowed by filter. $bundles_per_view_mode = array_intersect_key($bundles_per_view_mode, $media_embed_filter->settings['allowed_view_modes']); $bundles_per_view_mode = array_intersect_key($bundles_per_view_mode, $allowed_view_modes); // Configure view mode element styles. foreach (array_keys($all_view_modes) as $view_mode) { Loading core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php +54 −1 Original line number Diff line number Diff line Loading @@ -1219,7 +1219,14 @@ public function testViewMode() { 'enabled' => TRUE, 'label' => 'View Mode 3', ])->save(); // Enable view mode 1 & 2 and default for Image. EntityViewMode::create([ 'id' => 'media.view_mode_4', 'targetEntityType' => 'media', 'status' => TRUE, 'enabled' => TRUE, 'label' => 'View Mode 4', ])->save(); // Enable view mode 1, 2, 4 for Image. EntityViewDisplay::create([ 'id' => 'media.image.view_mode_1', 'targetEntityType' => 'media', Loading @@ -1234,6 +1241,13 @@ public function testViewMode() { 'bundle' => 'image', 'mode' => '22222', ])->save(); EntityViewDisplay::create([ 'id' => 'media.image.view_mode_4', 'targetEntityType' => 'media', 'status' => TRUE, 'bundle' => 'image', 'mode' => 'view_mode_4', ])->save(); $filter_format = FilterFormat::load('test_format'); $filter_format->setFilterConfig('media_embed', [ Loading Loading @@ -1423,6 +1437,45 @@ public function testViewMode() { $this->getSession()->reload(); $this->waitForEditor(); $assert_session->waitForElementVisible('css', 'article.media--view-mode-view-mode-1'); // Test that having a default_view_mode that is not an allowed_view_mode // will still be added to the editor. $filter_format->setFilterConfig('media_embed', [ 'status' => TRUE, 'settings' => [ 'default_view_mode' => 'view_mode_1', 'allowed_media_types' => [], 'allowed_view_modes' => [ '22222' => '22222', 'view_mode_4' => 'view_mode_4', ], ], ])->save(); // Test that the dependencies change when the allowed_view_modes change. $expected_config_dependencies = [ 'core.entity_view_mode.media.22222', 'core.entity_view_mode.media.view_mode_1', 'core.entity_view_mode.media.view_mode_4', ]; $dependencies = $filter_format->getDependencies(); $this->assertArrayHasKey('config', $dependencies); $this->assertEqualsCanonicalizing($expected_config_dependencies, $dependencies['config']); $this->host->body->value = '<drupal-media data-entity-type="media" data-entity-uuid="' . $this->media->uuid() . '" data-caption="baz"></drupal-media>'; $this->host->save(); // Reload page to get new configuration. $this->getSession()->reload(); $this->waitForEditor(); // Wait for the media preview to load. $this->assertNotEmpty($assert_session->waitForElementVisible('css', '.ck-widget.drupal-media img')); $this->click('.ck-widget.drupal-media'); $this->assertVisibleBalloon('[aria-label="Drupal Media toolbar"]'); $this->click('.ck-widget.drupal-media'); // Check that all three view modes exist including the default view mode // that was not originally included in the allowed_view_modes. $this->assertNotEmpty($this->getBalloonButton('View Mode 1')); $this->assertNotEmpty($this->getBalloonButton('View Mode 2 has Numeric ID')); $this->assertNotEmpty($this->getBalloonButton('View Mode 4')); } /** Loading Loading
core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Media.php +8 −1 Original line number Diff line number Diff line Loading @@ -80,6 +80,13 @@ private function configureViewModes(EditorInterface $editor) { $all_view_modes = $this->entityDisplayRepository->getViewModeOptions('media'); $allowed_view_modes = $media_embed_filter->settings['allowed_view_modes']; $default_view_mode = $media_embed_filter->settings['default_view_mode']; // @todo Remove in https://www.drupal.org/project/drupal/issues/3277049. // This is a workaround until the above issue is fixed to prevent the // editor from crashing because the frontend expects the default view mode // to exist in drupalElementStyles. if (!array_key_exists($default_view_mode, $allowed_view_modes)) { $allowed_view_modes[$default_view_mode] = $default_view_mode; } // Return early since there is no need to configure if there // are less than 2 view modes. if ($allowed_view_modes < 2) { Loading @@ -96,7 +103,7 @@ private function configureViewModes(EditorInterface $editor) { } } // Limit to view modes allowed by filter. $bundles_per_view_mode = array_intersect_key($bundles_per_view_mode, $media_embed_filter->settings['allowed_view_modes']); $bundles_per_view_mode = array_intersect_key($bundles_per_view_mode, $allowed_view_modes); // Configure view mode element styles. foreach (array_keys($all_view_modes) as $view_mode) { Loading
core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php +54 −1 Original line number Diff line number Diff line Loading @@ -1219,7 +1219,14 @@ public function testViewMode() { 'enabled' => TRUE, 'label' => 'View Mode 3', ])->save(); // Enable view mode 1 & 2 and default for Image. EntityViewMode::create([ 'id' => 'media.view_mode_4', 'targetEntityType' => 'media', 'status' => TRUE, 'enabled' => TRUE, 'label' => 'View Mode 4', ])->save(); // Enable view mode 1, 2, 4 for Image. EntityViewDisplay::create([ 'id' => 'media.image.view_mode_1', 'targetEntityType' => 'media', Loading @@ -1234,6 +1241,13 @@ public function testViewMode() { 'bundle' => 'image', 'mode' => '22222', ])->save(); EntityViewDisplay::create([ 'id' => 'media.image.view_mode_4', 'targetEntityType' => 'media', 'status' => TRUE, 'bundle' => 'image', 'mode' => 'view_mode_4', ])->save(); $filter_format = FilterFormat::load('test_format'); $filter_format->setFilterConfig('media_embed', [ Loading Loading @@ -1423,6 +1437,45 @@ public function testViewMode() { $this->getSession()->reload(); $this->waitForEditor(); $assert_session->waitForElementVisible('css', 'article.media--view-mode-view-mode-1'); // Test that having a default_view_mode that is not an allowed_view_mode // will still be added to the editor. $filter_format->setFilterConfig('media_embed', [ 'status' => TRUE, 'settings' => [ 'default_view_mode' => 'view_mode_1', 'allowed_media_types' => [], 'allowed_view_modes' => [ '22222' => '22222', 'view_mode_4' => 'view_mode_4', ], ], ])->save(); // Test that the dependencies change when the allowed_view_modes change. $expected_config_dependencies = [ 'core.entity_view_mode.media.22222', 'core.entity_view_mode.media.view_mode_1', 'core.entity_view_mode.media.view_mode_4', ]; $dependencies = $filter_format->getDependencies(); $this->assertArrayHasKey('config', $dependencies); $this->assertEqualsCanonicalizing($expected_config_dependencies, $dependencies['config']); $this->host->body->value = '<drupal-media data-entity-type="media" data-entity-uuid="' . $this->media->uuid() . '" data-caption="baz"></drupal-media>'; $this->host->save(); // Reload page to get new configuration. $this->getSession()->reload(); $this->waitForEditor(); // Wait for the media preview to load. $this->assertNotEmpty($assert_session->waitForElementVisible('css', '.ck-widget.drupal-media img')); $this->click('.ck-widget.drupal-media'); $this->assertVisibleBalloon('[aria-label="Drupal Media toolbar"]'); $this->click('.ck-widget.drupal-media'); // Check that all three view modes exist including the default view mode // that was not originally included in the allowed_view_modes. $this->assertNotEmpty($this->getBalloonButton('View Mode 1')); $this->assertNotEmpty($this->getBalloonButton('View Mode 2 has Numeric ID')); $this->assertNotEmpty($this->getBalloonButton('View Mode 4')); } /** Loading