diff --git a/core/modules/ckeditor/ckeditor.admin.inc b/core/modules/ckeditor/ckeditor.admin.inc index 4ee12bb..21be21d 100644 --- a/core/modules/ckeditor/ckeditor.admin.inc +++ b/core/modules/ckeditor/ckeditor.admin.inc @@ -7,7 +7,6 @@ use Drupal\Component\Utility\Html; use Drupal\Core\Template\Attribute; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Language\LanguageInterface; /** @@ -66,10 +65,10 @@ function template_preprocess_ckeditor_settings_toolbar(&$variables) { $build_button_item = function($button, $rtl) { // Value of the button item. if (isset($button['image_alternative' . $rtl])) { - $value = SafeMarkup::set($button['image_alternative' . $rtl]); + $value = $button['image_alternative' . $rtl]; } elseif (isset($button['image_alternative'])) { - $value = SafeMarkup::set($button['image_alternative']); + $value = $button['image_alternative']; } elseif (isset($button['image'])) { $value = array( diff --git a/core/modules/ckeditor/src/Plugin/CKEditorPlugin/Internal.php b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/Internal.php index c405c7f..2385511 100644 --- a/core/modules/ckeditor/src/Plugin/CKEditorPlugin/Internal.php +++ b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/Internal.php @@ -127,7 +127,18 @@ public function getConfig(Editor $editor) { */ public function getButtons() { $button = function($name, $direction = 'ltr') { - return '' . $name . ''; + // In the markup below, we mostly use the name (which may include spaces), + // but in one spot we use it as a CSS class, so strip spaces. + $class_name = str_replace(' ', '', $name); + return [ + '#type' => 'inline_template', + '#template' => '{{ name }}', + '#context' => [ + 'direction' => $direction, + 'name' => $name, + 'classname' => $class_name, + ], + ]; }; return array( @@ -256,7 +267,13 @@ public function getButtons() { ), 'Format' => array( 'label' => t('HTML block format'), - 'image_alternative' => '' . t('Format') . '', + 'image_alternative' => [ + '#type' => 'inline_template', + '#template' => '{{ format_text }}', + '#context' => [ + 'format_text' => t('Format'), + ], + ], ), // "table" plugin. 'Table' => array( @@ -282,7 +299,13 @@ public function getButtons() { // No plugin, separator "button" for toolbar builder UI use only. '-' => array( 'label' => t('Separator'), - 'image_alternative' => '', + 'image_alternative' => [ + '#type' => 'inline_template', + '#template' => '', + '#context' => [ + 'button_separator_text' => t('Button separator'), + ], + ], 'attributes' => array( 'class' => array('ckeditor-button-separator'), 'data-drupal-ckeditor-type' => 'separator', diff --git a/core/modules/ckeditor/src/Plugin/CKEditorPlugin/StylesCombo.php b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/StylesCombo.php index d569930..d3eb49f 100644 --- a/core/modules/ckeditor/src/Plugin/CKEditorPlugin/StylesCombo.php +++ b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/StylesCombo.php @@ -59,7 +59,13 @@ public function getButtons() { return array( 'Styles' => array( 'label' => t('Font style'), - 'image_alternative' => '' . t('Styles') . '', + 'image_alternative' => [ + '#type' => 'inline_template', + '#template' => '{{ styles_text }}', + '#context' => [ + 'styles_text' => t('Styles'), + ], + ], ), ); } diff --git a/core/modules/ckeditor/src/Tests/CKEditorAdminTest.php b/core/modules/ckeditor/src/Tests/CKEditorAdminTest.php index 3ce8271..ca1954f 100644 --- a/core/modules/ckeditor/src/Tests/CKEditorAdminTest.php +++ b/core/modules/ckeditor/src/Tests/CKEditorAdminTest.php @@ -7,6 +7,7 @@ namespace Drupal\ckeditor\Tests; +use Drupal\Component\Serialization\Json; use Drupal\editor\Entity\Editor; use Drupal\filter\FilterFormatInterface; use Drupal\simpletest\WebTestBase; @@ -176,6 +177,22 @@ function testExistingFormat() { $this->assertTrue($editor instanceof Editor, 'An Editor config entity exists.'); $this->assertIdentical($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.'); + // Check that the markup we're setting for the toolbar buttons (actually in + // JavaScript's drupalSettings, and Unicode-escaped) is correctly rendered. + $this->drupalGet('admin/config/content/formats/manage/filtered_html'); + // Create function to encode HTML as we expect it in drupalSettings. + $json_encode = function($html) { + return trim(Json::encode($html), '"'); + }; + // Check the Button separator. + $this->assertRaw($json_encode('
  • ')); + // Check the Format dropdown. + $this->assertRaw($json_encode('
  • Format
  • ')); + // Check the Styles dropdown. + $this->assertRaw($json_encode('
  • Styles
  • ')); + // Check strikethrough. + $this->assertRaw($json_encode('
  • strike
  • ')); + // Now enable the ckeditor_test module, which provides one configurable // CKEditor plugin — this should not affect the Editor config entity. \Drupal::service('module_installer')->install(array('ckeditor_test'));