Skip to content
Snippets Groups Projects
Unverified Commit 25feeac2 authored by rob_pr's avatar rob_pr Committed by Lucas Hedding
Browse files

Issue #3396696 by rob_pr, heddn: Type error in DomApplyStyles plugin when using CKEditor5

parent c31442a2
Branches
Tags
No related merge requests found
Pipeline #56948 failed
......@@ -126,12 +126,21 @@ class DomApplyStyles extends DomProcessBase implements ContainerFactoryPluginInt
$message = 'The "format" option must be a non-empty string.';
throw new InvalidPluginDefinitionException($this->getPluginId(), $message);
}
$editor_styles = $this->configFactory
->get("editor.editor.$format")
->get('settings.plugins.stylescombo.styles');
foreach (explode("\r\n", $editor_styles) as $rule) {
if (preg_match('/(.*)\|(.*)/', $rule, $matches)) {
$this->styles[$matches[2]] = $matches[1];
$editor_config = $this->configFactory->get("editor.editor.$format");
if ($editor_config->get('editor') === 'ckeditor') {
$editor_styles = $editor_config->get('settings.plugins.stylescombo.styles') ?? '';
foreach (explode("\r\n", $editor_styles) as $rule) {
if (preg_match('/(.*)\|(.*)/', $rule, $matches)) {
$this->styles[$matches[2]] = $matches[1];
}
}
}
else if ($editor_config->get('editor') === 'ckeditor5') {
$editor_styles = $editor_config->get('settings.plugins.ckeditor5_style.styles') ?? [];
foreach ($editor_styles as $editor_style) {
if (preg_match('/<(.*) class="(.*)">/', $editor_style['element'], $matches)) {
$this->styles[$editor_style['label']] = $matches[1] . '.' . $matches[2];
}
}
}
}
......
......@@ -51,6 +51,9 @@ final class DomApplyStylesTest extends MigrateProcessTestCase {
protected function setUp(): void {
// Mock a config object.
$prophecy = $this->prophesize(ImmutableConfig::class);
$prophecy
->get('editor')
->willReturn('ckeditor');
$prophecy
->get('settings.plugins.stylescombo.styles')
->willReturn("strong.foo|Bold\r\nem.foo.bar|Italic\r\n");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment