Commit db37224c authored by catch's avatar catch
Browse files

Issue #2501711 by cwells, alexpott: Remove or document SafeMarkup::set in...

Issue #2501711 by cwells, alexpott: Remove or document SafeMarkup::set in template_preprocess_ckeditor_settings_toolbar
parent c737410a
......@@ -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(
......
......@@ -127,7 +127,18 @@ public function getConfig(Editor $editor) {
*/
public function getButtons() {
$button = function($name, $direction = 'ltr') {
return '<a href="#" class="cke-icon-only cke_' . $direction . '" role="button" title="' . $name . '" aria-label="' . $name . '"><span class="cke_button_icon cke_button__' . str_replace(' ', '', $name) . '_icon">' . $name . '</span></a>';
// 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' => '<a href="#" class="cke-icon-only cke_{{ direction }}" role="button" title="{{ name }}" aria-label="{{ name }}"><span class="cke_button_icon cke_button__{{ classname }}_icon">{{ name }}</span></a>',
'#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' => '<a href="#" role="button" aria-label="' . t('Format') . '"><span class="ckeditor-button-dropdown">' . t('Format') . '<span class="ckeditor-button-arrow"></span></span></a>',
'image_alternative' => [
'#type' => 'inline_template',
'#template' => '<a href="#" role="button" aria-label="{{ format_text }}"><span class="ckeditor-button-dropdown">{{ format_text }}<span class="ckeditor-button-arrow"></span></span></a>',
'#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' => '<a href="#" role="button" aria-label="' . t('Button separator') . '" class="ckeditor-separator"></a>',
'image_alternative' => [
'#type' => 'inline_template',
'#template' => '<a href="#" role="button" aria-label="{{ button_separator_text }}" class="ckeditor-separator"></a>',
'#context' => [
'button_separator_text' => t('Button separator'),
],
],
'attributes' => array(
'class' => array('ckeditor-button-separator'),
'data-drupal-ckeditor-type' => 'separator',
......
......@@ -59,7 +59,13 @@ public function getButtons() {
return array(
'Styles' => array(
'label' => t('Font style'),
'image_alternative' => '<a href="#" role="button" aria-label="' . t('Styles') . '"><span class="ckeditor-button-dropdown">' . t('Styles') . '<span class="ckeditor-button-arrow"></span></span></a>',
'image_alternative' => [
'#type' => 'inline_template',
'#template' => '<a href="#" role="button" aria-label="{{ styles_text }}"><span class="ckeditor-button-dropdown">{{ styles_text }}<span class="ckeditor-button-arrow"></span></span></a>',
'#context' => [
'styles_text' => t('Styles'),
],
],
),
);
}
......
......@@ -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('<li data-drupal-ckeditor-button-name="-" class="ckeditor-button-separator ckeditor-multiple-button" data-drupal-ckeditor-type="separator"><a href="#" role="button" aria-label="Button separator" class="ckeditor-separator"></a></li>'));
// Check the Format dropdown.
$this->assertRaw($json_encode('<li data-drupal-ckeditor-button-name="Format" class="ckeditor-button"><a href="#" role="button" aria-label="Format"><span class="ckeditor-button-dropdown">Format<span class="ckeditor-button-arrow"></span></span></a></li>'));
// Check the Styles dropdown.
$this->assertRaw($json_encode('<li data-drupal-ckeditor-button-name="Styles" class="ckeditor-button"><a href="#" role="button" aria-label="Styles"><span class="ckeditor-button-dropdown">Styles<span class="ckeditor-button-arrow"></span></span></a></li>'));
// Check strikethrough.
$this->assertRaw($json_encode('<li data-drupal-ckeditor-button-name="Strike" class="ckeditor-button"><a href="#" class="cke-icon-only cke_ltr" role="button" title="strike" aria-label="strike"><span class="cke_button_icon cke_button__strike_icon">strike</span></a></li>'));
// 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'));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment