diff --git a/core/modules/ckeditor/config/schema/ckeditor.schema.yml b/core/modules/ckeditor/config/schema/ckeditor.schema.yml index fcababfa0f25d52ab69d234cd5835e64a443b34d..528919d41f0afff9b243329d24d3e70fcc9b705a 100644 --- a/core/modules/ckeditor/config/schema/ckeditor.schema.yml +++ b/core/modules/ckeditor/config/schema/ckeditor.schema.yml @@ -48,5 +48,5 @@ ckeditor.plugin.stylescombo: label: 'Styles dropdown' mapping: styles: - type: label + type: text label: 'List of styles' diff --git a/core/modules/ckeditor/tests/src/Functional/CKEditorStylesComboTranslationTest.php b/core/modules/ckeditor/tests/src/Functional/CKEditorStylesComboTranslationTest.php new file mode 100644 index 0000000000000000000000000000000000000000..27fabffbf7853abb9d706a04b1428ac1e9cce583 --- /dev/null +++ b/core/modules/ckeditor/tests/src/Functional/CKEditorStylesComboTranslationTest.php @@ -0,0 +1,85 @@ +format = strtolower($this->randomMachineName()); + $filter_format = FilterFormat::create([ + 'format' => $this->format, + 'name' => $this->randomString(), + 'filters' => [], + ]); + $filter_format->save(); + $editor = Editor::create([ + 'format' => $this->format, + 'editor' => 'ckeditor', + ]); + $editor->save(); + + $this->adminUser = $this->drupalCreateUser(['administer filters', 'translate configuration']); + + ConfigurableLanguage::createFromLangcode('de')->save(); + } + + /** + * Tests translations of CKEditor styles configuration. + */ + public function testExistingFormat() { + $this->drupalLogin($this->adminUser); + $edit = [ + 'editor[settings][plugins][stylescombo][styles]' => 'h1.title|Title', + ]; + $this->drupalPostForm('admin/config/content/formats/manage/' . $this->format, $edit, 'Save configuration'); + + $this->drupalGet('admin/config/content/formats/manage/' . $this->format . '/translate/de/add'); + $this->assertEquals('textarea', $this->assertSession()->fieldExists('List of styles')->getTagName()); + $this->assertSession()->fieldValueEquals('List of styles', 'h1.title|Title'); + + $page = $this->getSession()->getPage(); + $page->fillField('List of styles', 'h1.title|Titel'); + $page->pressButton('Save translation'); + $this->assertSession()->pageTextContains('Successfully saved German translation.'); + } + +} diff --git a/core/modules/editor/editor.services.yml b/core/modules/editor/editor.services.yml index 731215ccbd111f4f9bfeefe06c27fb89c7ad2419..1a60125bbcc0b9b54bf0a36d44d08c4e7ff27ea5 100644 --- a/core/modules/editor/editor.services.yml +++ b/core/modules/editor/editor.services.yml @@ -5,3 +5,8 @@ services: element.editor: class: Drupal\editor\Element arguments: ['@plugin.manager.editor'] + editor.config_translation_mapper_subscriber: + class: Drupal\editor\EventSubscriber\EditorConfigTranslationSubscriber + arguments: ['@config.factory'] + tags: + - {name: event_subscriber} diff --git a/core/modules/editor/src/EventSubscriber/EditorConfigTranslationSubscriber.php b/core/modules/editor/src/EventSubscriber/EditorConfigTranslationSubscriber.php new file mode 100644 index 0000000000000000000000000000000000000000..eb43ddc6b53a08be3a771e5850458bf0470eda74 --- /dev/null +++ b/core/modules/editor/src/EventSubscriber/EditorConfigTranslationSubscriber.php @@ -0,0 +1,62 @@ +configFactory = $config_factory; + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() { + $events = []; + if (class_exists('Drupal\config_translation\Event\ConfigTranslationEvents')) { + $events[ConfigTranslationEvents::POPULATE_MAPPER][] = ['addConfigNames']; + } + return $events; + } + + /** + * Reacts to the populating of a configuration mapper. + * + * @param \Drupal\config_translation\Event\ConfigMapperPopulateEvent $event + * The configuration mapper event. + */ + public function addConfigNames(ConfigMapperPopulateEvent $event) { + $mapper = $event->getMapper(); + if ($mapper instanceof ConfigEntityMapper && $mapper->getType() == 'filter_format') { + $editor_config_name = 'editor.editor.' . $mapper->getEntity()->id(); + // Only add the text editor config if it exists, otherwise we assume no + // editor has been set for this text format. + if (!$this->configFactory->get($editor_config_name)->isNew()) { + $mapper->addConfigName($editor_config_name); + } + } + } + +}