commit 33b7bea729491142e85f3472443d9948975936e0 Author: Joel Pittet Date: Sat Aug 16 16:20:14 2014 -0700 refactor diff --git a/core/modules/ckeditor/ckeditor.admin.inc b/core/modules/ckeditor/ckeditor.admin.inc index c14ad79..7e3ae47 100644 --- a/core/modules/ckeditor/ckeditor.admin.inc +++ b/core/modules/ckeditor/ckeditor.admin.inc @@ -60,43 +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) { + $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']); + + // Add language direction property. + $button['language_direction'] = $language_direction; // Check for the image button to be present and convert URI to URL. - if (isset($button['image'])) { - $button['image'] = file_create_url($button['image' . $rtl]); - } - // Build the button item. - // Clone $button and remove unwanted array keys for HTML rendering. - $button_build = $button; - unset($button_build['group']); - unset($button_build['attributes']); - unset($button_build['multiple']); - $button_item = $button_build + array( - 'rtl' => $rtl, - 'attributes' => new Attribute($attributes), - ); - // If this button has group information, add it to the attributes. - if (!empty($button['group'])) { - $button_item['group'] = $button['group']; + $rtl = $language_direction === 'rtl' ? '_rtl' : ''; + if (isset($button['image' . $rtl])) { + $button['image_url'] = file_create_url($button['image' . $rtl]); } - - return $button_item; + return $button; }; // Assemble list of disabled buttons (which are always a single row). @@ -111,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 b13c88c..c7450f8 100644 --- a/core/modules/ckeditor/src/Plugin/CKEditorPlugin/Internal.php +++ b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/Internal.php @@ -146,43 +146,43 @@ public function getButtons() { ), 'Superscript' => array( 'label' => t('Superscript'), - 'image_alternative' => 'super script', + 'image_alternative' => 'superscript', ), 'Subscript' => array( 'label' => t('Subscript'), - 'image_alternative' => 'sub script', + 'image_alternative' => 'subscript', ), // "removeformat" plugin. 'RemoveFormat' => array( 'label' => t('Remove format'), - 'image_alternative' => 'remove format', + 'image_alternative' => 'removeformat', ), // "justify" plugin. 'JustifyLeft' => array( 'label' => t('Align left'), - 'image_alternative' => 'justify left', + 'image_alternative' => 'justifyleft', ), 'JustifyCenter' => array( 'label' => t('Align center'), - 'image_alternative' => 'justify center', + 'image_alternative' => 'justifycenter', ), 'JustifyRight' => array( 'label' => t('Align right'), - 'image_alternative' => 'justify right', + 'image_alternative' => 'justifyright', ), 'JustifyBlock' => array( 'label' => t('Justify'), - 'image_alternative' => 'justify block', + 'image_alternative' => 'justifyblock', ), // "list" plugin. 'BulletedList' => array( 'label' => t('Bullet list'), - 'image_alternative' => 'bulleted list', + 'image_alternative' => 'bulletedlist', 'image_alternative_rtl' => TRUE, ), 'NumberedList' => array( 'label' => t('Numbered list'), - 'image_alternative' => 'numbered list', + 'image_alternative' => 'numberedlist', 'image_alternative_rtl' => TRUE, ), // "indent" plugin. @@ -215,7 +215,7 @@ public function getButtons() { // "horizontalrule" plugin 'HorizontalRule' => array( 'label' => t('Horizontal rule'), - 'image_alternative' => 'horizontal rule', + 'image_alternative' => 'horizontalrule', ), // "clipboard" plugin. 'Cut' => array( @@ -236,19 +236,19 @@ public function getButtons() { // "pastetext" plugin. 'PasteText' => array( 'label' => t('Paste Text'), - 'image_alternative' => 'paste text', + 'image_alternative' => 'pastetext', 'image_alternative_rtl' => TRUE, ), // "pastefromword" plugin. 'PasteFromWord' => array( 'label' => t('Paste from Word'), - 'image_alternative' => 'paste from word', + 'image_alternative' => 'pastefromword', 'image_alternative_rtl' => TRUE, ), // "specialchar" plugin. 'SpecialChar' => array( 'label' => t('Character map'), - 'image_alternative' => 'special char', + 'image_alternative' => 'specialchar', ), 'Format' => array( 'label' => t('HTML block format'), @@ -263,7 +263,7 @@ public function getButtons() { // "showblocks" plugin. 'ShowBlocks' => array( 'label' => t('Show blocks'), - 'image_alternative' => 'show blocks', + 'image_alternative' => 'showblocks', 'image_alternative_rtl' => TRUE, ), // "sourcearea" plugin. diff --git a/core/modules/ckeditor/templates/ckeditor-settings-toolbar.html.twig b/core/modules/ckeditor/templates/ckeditor-settings-toolbar.html.twig index 5d16a45..5d85f50 100644 --- a/core/modules/ckeditor/templates/ckeditor-settings-toolbar.html.twig +++ b/core/modules/ckeditor/templates/ckeditor-settings-toolbar.html.twig @@ -16,25 +16,21 @@ {% macro button(button) %} {# Value of the button item. #} {% if button.image_alternative %} - {% if button.image_alternative == 'format' %} - - {{ button.button_text }} - - {% elseif button.image_alternative == 'styles' %} - - {{ button.button_text }} - - {% elseif button.image_alternative == 'separator' %} - - {% else %} - - {{ button.label }} - - {% endif %} - {% elseif button.image %} + {% 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 }} + {{ button.label }} {% else %}