Issue #3276670 by hooroomoo, Wim Leers: Some configurations of allowed view modes cause CKE to fail to initialize
parent
759f9c5356
commit
44f5e5c5c8
|
@ -80,6 +80,13 @@ class Media extends CKEditor5PluginDefault implements ContainerFactoryPluginInte
|
||||||
$all_view_modes = $this->entityDisplayRepository->getViewModeOptions('media');
|
$all_view_modes = $this->entityDisplayRepository->getViewModeOptions('media');
|
||||||
$allowed_view_modes = $media_embed_filter->settings['allowed_view_modes'];
|
$allowed_view_modes = $media_embed_filter->settings['allowed_view_modes'];
|
||||||
$default_view_mode = $media_embed_filter->settings['default_view_mode'];
|
$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
|
// Return early since there is no need to configure if there
|
||||||
// are less than 2 view modes.
|
// are less than 2 view modes.
|
||||||
if ($allowed_view_modes < 2) {
|
if ($allowed_view_modes < 2) {
|
||||||
|
@ -96,7 +103,7 @@ class Media extends CKEditor5PluginDefault implements ContainerFactoryPluginInte
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Limit to view modes allowed by filter.
|
// 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.
|
// Configure view mode element styles.
|
||||||
foreach (array_keys($all_view_modes) as $view_mode) {
|
foreach (array_keys($all_view_modes) as $view_mode) {
|
||||||
|
|
|
@ -1219,7 +1219,14 @@ class MediaTest extends WebDriverTestBase {
|
||||||
'enabled' => TRUE,
|
'enabled' => TRUE,
|
||||||
'label' => 'View Mode 3',
|
'label' => 'View Mode 3',
|
||||||
])->save();
|
])->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([
|
EntityViewDisplay::create([
|
||||||
'id' => 'media.image.view_mode_1',
|
'id' => 'media.image.view_mode_1',
|
||||||
'targetEntityType' => 'media',
|
'targetEntityType' => 'media',
|
||||||
|
@ -1234,6 +1241,13 @@ class MediaTest extends WebDriverTestBase {
|
||||||
'bundle' => 'image',
|
'bundle' => 'image',
|
||||||
'mode' => '22222',
|
'mode' => '22222',
|
||||||
])->save();
|
])->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 = FilterFormat::load('test_format');
|
||||||
$filter_format->setFilterConfig('media_embed', [
|
$filter_format->setFilterConfig('media_embed', [
|
||||||
|
@ -1423,6 +1437,45 @@ class MediaTest extends WebDriverTestBase {
|
||||||
$this->getSession()->reload();
|
$this->getSession()->reload();
|
||||||
$this->waitForEditor();
|
$this->waitForEditor();
|
||||||
$assert_session->waitForElementVisible('css', 'article.media--view-mode-view-mode-1');
|
$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…
Reference in New Issue