diff --git a/core/modules/ckeditor/ckeditor.admin.inc b/core/modules/ckeditor/ckeditor.admin.inc index 220ec77..7e3ae47 100644 --- a/core/modules/ckeditor/ckeditor.admin.inc +++ b/core/modules/ckeditor/ckeditor.admin.inc @@ -6,7 +6,6 @@ */ use Drupal\Core\Template\Attribute; -use Drupal\Component\Utility\SafeMarkup; /** * Prepares variables for CKEditor settings toolbar templates. @@ -61,54 +60,25 @@ function template_preprocess_ckeditor_settings_toolbar(&$variables) { } $disabled_buttons = array_diff_key($buttons, $multiple_buttons); - $rtl = $language_direction === 'rtl' ? '_rtl' : ''; - - $build_button_item = function($button, $rtl) { - // Value of the button item. - if (isset($button['image_alternative' . $rtl])) { - $value = SafeMarkup::set($button['image_alternative' . $rtl]); - } - elseif (isset($button['image_alternative'])) { - $value = SafeMarkup::set($button['image_alternative']); - } - elseif (isset($button['image'])) { - $value = array( - '#theme' => 'image', - '#uri' => $button['image' . $rtl], - '#title' => $button['label'], - '#prefix' => '', - '#suffix' => '', - ); - } - else { - $value = '?'; - } - + $build_button_item = function($button, $language_direction) { // Set additional attribute on the button if it can occur multiple times. if (!empty($button['multiple'])) { $button['attributes']['class'][] = 'ckeditor-multiple-button'; } - // Build the button attributes. - $attributes = array( - 'data-drupal-ckeditor-button-name' => $button['name'], - 'class' => array('ckeditor-button'), - ); - if (!empty($button['attributes'])) { - $attributes = array_merge($attributes, $button['attributes']); - } + $button['attributes']['data-drupal-ckeditor-button-name'] = $button['name']; + $button['attributes']['class'][] = 'ckeditor-button'; + $button['attributes'] = new Attribute($button['attributes']); - // Build the button item. - $button_item = array( - 'value' => $value, - 'attributes' => new Attribute($attributes), - ); - // If this button has group information, add it to the attributes. - if (!empty($button['group'])) { - $button_item['group'] = $button['group']; - } + // Add language direction property. + $button['language_direction'] = $language_direction; - return $button_item; + // Check for the image button to be present and convert URI to URL. + $rtl = $language_direction === 'rtl' ? '_rtl' : ''; + if (isset($button['image' . $rtl])) { + $button['image_url'] = file_create_url($button['image' . $rtl]); + } + return $button; }; // Assemble list of disabled buttons (which are always a single row). @@ -123,18 +93,18 @@ function template_preprocess_ckeditor_settings_toolbar(&$variables) { return $button['group'] === $group_name; }); foreach ($buttons as $button) { - $variables['active_buttons'][$row_number][$group_name]['buttons'][] = $build_button_item($button, $rtl); + $variables['active_buttons'][$row_number][$group_name]['buttons'][] = $build_button_item($button, $language_direction); } } } // Assemble list of disabled buttons (which are always a single row). $variables['disabled_buttons'] = array(); foreach ($disabled_buttons as $button) { - $variables['disabled_buttons'][] = $build_button_item($button, $rtl); + $variables['disabled_buttons'][] = $build_button_item($button, $language_direction); } // Assemble list of multiple buttons that may be added multiple times. $variables['multiple_buttons'] = array(); foreach ($multiple_buttons as $button) { - $variables['multiple_buttons'][] = $build_button_item($button, $rtl); + $variables['multiple_buttons'][] = $build_button_item($button, $language_direction); } } diff --git a/core/modules/ckeditor/src/Plugin/CKEditorPlugin/Internal.php b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/Internal.php index 02049b6..c7450f8 100644 --- a/core/modules/ckeditor/src/Plugin/CKEditorPlugin/Internal.php +++ b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/Internal.php @@ -125,163 +125,162 @@ public function getConfig(Editor $editor) { * Implements \Drupal\ckeditor\Plugin\CKEditorPluginButtonsInterface::getButtons(). */ public function getButtons() { - $button = function($name, $direction = 'ltr') { - return '' . $name . ''; - }; return array( // "basicstyles" plugin. 'Bold' => array( 'label' => t('Bold'), - 'image_alternative' => $button('bold'), + 'image_alternative' => 'bold', ), 'Italic' => array( 'label' => t('Italic'), - 'image_alternative' => $button('italic'), + 'image_alternative' => 'italic', ), 'Underline' => array( 'label' => t('Underline'), - 'image_alternative' => $button('underline'), + 'image_alternative' => 'underline', ), 'Strike' => array( 'label' => t('Strike-through'), - 'image_alternative' => $button('strike'), + 'image_alternative' => 'strike', ), 'Superscript' => array( 'label' => t('Superscript'), - 'image_alternative' => $button('super script'), + 'image_alternative' => 'superscript', ), 'Subscript' => array( 'label' => t('Subscript'), - 'image_alternative' => $button('sub script'), + 'image_alternative' => 'subscript', ), // "removeformat" plugin. 'RemoveFormat' => array( 'label' => t('Remove format'), - 'image_alternative' => $button('remove format'), + 'image_alternative' => 'removeformat', ), // "justify" plugin. 'JustifyLeft' => array( 'label' => t('Align left'), - 'image_alternative' => $button('justify left'), + 'image_alternative' => 'justifyleft', ), 'JustifyCenter' => array( 'label' => t('Align center'), - 'image_alternative' => $button('justify center'), + 'image_alternative' => 'justifycenter', ), 'JustifyRight' => array( 'label' => t('Align right'), - 'image_alternative' => $button('justify right'), + 'image_alternative' => 'justifyright', ), 'JustifyBlock' => array( 'label' => t('Justify'), - 'image_alternative' => $button('justify block'), + 'image_alternative' => 'justifyblock', ), // "list" plugin. 'BulletedList' => array( 'label' => t('Bullet list'), - 'image_alternative' => $button('bulleted list'), - 'image_alternative_rtl' => $button('bulleted list', 'rtl'), + 'image_alternative' => 'bulletedlist', + 'image_alternative_rtl' => TRUE, ), 'NumberedList' => array( 'label' => t('Numbered list'), - 'image_alternative' => $button('numbered list'), - 'image_alternative_rtl' => $button('numbered list', 'rtl'), + 'image_alternative' => 'numberedlist', + 'image_alternative_rtl' => TRUE, ), // "indent" plugin. 'Outdent' => array( 'label' => t('Outdent'), - 'image_alternative' => $button('outdent'), - 'image_alternative_rtl' => $button('outdent', 'rtl'), + 'image_alternative' => 'outdent', + 'image_alternative_rtl' => TRUE, ), 'Indent' => array( 'label' => t('Indent'), - 'image_alternative' => $button('indent'), - 'image_alternative_rtl' => $button('indent', 'rtl'), + 'image_alternative' => 'indent', + 'image_alternative_rtl' => TRUE, ), // "undo" plugin. 'Undo' => array( 'label' => t('Undo'), - 'image_alternative' => $button('undo'), - 'image_alternative_rtl' => $button('undo', 'rtl'), + 'image_alternative' => 'undo', + 'image_alternative_rtl' => TRUE, ), 'Redo' => array( 'label' => t('Redo'), - 'image_alternative' => $button('redo'), - 'image_alternative_rtl' => $button('redo', 'rtl'), + 'image_alternative' => 'redo', + 'image_alternative_rtl' => TRUE, ), // "blockquote" plugin. 'Blockquote' => array( 'label' => t('Blockquote'), - 'image_alternative' => $button('blockquote'), + 'image_alternative' => 'blockquote', ), // "horizontalrule" plugin 'HorizontalRule' => array( 'label' => t('Horizontal rule'), - 'image_alternative' => $button('horizontal rule'), + 'image_alternative' => 'horizontalrule', ), // "clipboard" plugin. 'Cut' => array( 'label' => t('Cut'), - 'image_alternative' => $button('cut'), - 'image_alternative_rtl' => $button('cut', 'rtl'), + 'image_alternative' => 'cut', + 'image_alternative_rtl' => TRUE, ), 'Copy' => array( 'label' => t('Copy'), - 'image_alternative' => $button('copy'), - 'image_alternative_rtl' => $button('copy', 'rtl'), + 'image_alternative' => 'copy', + 'image_alternative_rtl' => TRUE, ), 'Paste' => array( 'label' => t('Paste'), - 'image_alternative' => $button('paste'), - 'image_alternative_rtl' => $button('paste', 'rtl'), + 'image_alternative' => 'paste', + 'image_alternative_rtl' => TRUE, ), // "pastetext" plugin. 'PasteText' => array( 'label' => t('Paste Text'), - 'image_alternative' => $button('paste text'), - 'image_alternative_rtl' => $button('paste text', 'rtl'), + 'image_alternative' => 'pastetext', + 'image_alternative_rtl' => TRUE, ), // "pastefromword" plugin. 'PasteFromWord' => array( 'label' => t('Paste from Word'), - 'image_alternative' => $button('paste from word'), - 'image_alternative_rtl' => $button('paste from word', 'rtl'), + 'image_alternative' => 'pastefromword', + 'image_alternative_rtl' => TRUE, ), // "specialchar" plugin. 'SpecialChar' => array( 'label' => t('Character map'), - 'image_alternative' => $button('special char'), + 'image_alternative' => 'specialchar', ), 'Format' => array( 'label' => t('HTML block format'), - 'image_alternative' => '' . t('Format') . '', + 'button_text' => t('Format'), + 'image_alternative' => 'format', ), // "table" plugin. 'Table' => array( 'label' => t('Table'), - 'image_alternative' => $button('table'), + 'image_alternative' => 'table', ), // "showblocks" plugin. 'ShowBlocks' => array( 'label' => t('Show blocks'), - 'image_alternative' => $button('show blocks'), - 'image_alternative_rtl' => $button('show blocks', 'rtl'), + 'image_alternative' => 'showblocks', + 'image_alternative_rtl' => TRUE, ), // "sourcearea" plugin. 'Source' => array( 'label' => t('Source code'), - 'image_alternative' => $button('source'), + 'image_alternative' => 'source', ), // "maximize" plugin. 'Maximize' => array( 'label' => t('Maximize'), - 'image_alternative' => $button('maximize'), + 'image_alternative' => 'maximize', ), // No plugin, separator "button" for toolbar builder UI use only. '-' => array( 'label' => t('Separator'), - 'image_alternative' => '', + 'image_alternative' => 'separator', + 'button_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 963436d..40fd9c4 100644 --- a/core/modules/ckeditor/src/Plugin/CKEditorPlugin/StylesCombo.php +++ b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/StylesCombo.php @@ -59,7 +59,8 @@ public function getButtons() { return array( 'Styles' => array( 'label' => t('Font style'), - 'image_alternative' => '' . t('Styles') . '', + 'button_text' => t('Styles'), + 'image_alternative' => 'styles', ), ); } diff --git a/core/modules/ckeditor/templates/ckeditor-settings-toolbar.html.twig b/core/modules/ckeditor/templates/ckeditor-settings-toolbar.html.twig index 18d3558..5d85f50 100644 --- a/core/modules/ckeditor/templates/ckeditor-settings-toolbar.html.twig +++ b/core/modules/ckeditor/templates/ckeditor-settings-toolbar.html.twig @@ -13,6 +13,33 @@ * @ingroup themeable */ #} +{% macro button(button) %} + {# Value of the button item. #} + {% if button.image_alternative %} + {% if button.image_alternative in ['format', 'styles'] %} + + {{ button.button_text }} + + {% elseif button.image_alternative == 'separator' %} + + {% else %} + + {{ button.label }} + + {% endif %} + {% elseif button.image_url %} + + + {{ button.label }} + + + {% else %} + ? + {% endif %} +{% endmacro %} + +{% import _self as ckeditor %} + {% spaceless %}
{{ 'Toolbar configuration'|t }} @@ -28,7 +55,7 @@ @@ -37,7 +64,7 @@ @@ -56,7 +83,7 @@

{{ group_name }}

@@ -68,6 +95,7 @@ {% endfor %} +