Problem/Motivation

Discovered while re-rolling #2306515: SafeMarkup in CKEditor toolbar configuration UI — fix by not generating markup in PHP but using Twig Macros.
If the site is installed with any of the RTL based languages then the CKEditor toolbar buttons have below issues.

  1. ISSUE #1:Image buttons do not recognize the language direction change. So no image button appears in the toolbar.
  2. ISSUE #2The image alternative buttons show inline texts. This is caused by the CSS class ".cke-icon-only". This class doesn't recognize the language direction change.


RTL - Click to enlarge

Step(s) to replicate

  1. Install latest Drupal 8.x beta in https://simplytest.me/ with language selected as Arabic (ar).
  2. Navigate to admin/config/content/formats/manage/full_html and see the toolbar buttons.

Proposed resolution

  • Image buttons should consider the language direction change. Plugins should call the "LanguageInterface" to determine the language change.
  • Need to implement a css class that should consider direction as rtl.

Remaining tasks

  1. For issue #1, write a test case and validate.
  2. For issue #2, manual testing is required.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Comments

aneek created an issue. See original summary.

aneek’s picture

StatusFileSize
new2.53 KB
new10.42 KB

Uploading fail & pass patches to test.

aneek’s picture

Status: Active » Needs review

The last submitted patch, 2: 2563543-02-fail.patch, failed testing.

wim leers’s picture

Status: Needs review » Needs work
StatusFileSize
new151.71 KB
new152.18 KB

I tested this, with beta 15 versus HEAD plus the patch (https://simplytest.me/project/drupal/8.x?patch[]=https://www.drupal.org/...). Unfortunately, I don't see any difference before vs after.

  1. +++ b/core/modules/ckeditor/ckeditor.admin.inc
    @@ -70,7 +70,7 @@ function template_preprocess_ckeditor_settings_toolbar(&$variables) {
    -    elseif (isset($button['image'])) {
    +    elseif (isset($button['image' . $rtl]) ) {
    
    +++ b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalImage.php
    @@ -53,10 +54,12 @@ public function getConfig(Editor $editor) {
       public function getButtons() {
    +    $language_interface = \Drupal::languageManager()->getCurrentLanguage();
    +    $rtl = $language_interface->getDirection() === LanguageInterface::DIRECTION_RTL ? '_rtl' : '';
         return array(
           'DrupalImage' => array(
             'label' => t('Image'),
    -        'image' => drupal_get_path('module', 'ckeditor') . '/js/plugins/drupalimage/image.png',
    +        'image' . $rtl => drupal_get_path('module', 'ckeditor') . '/js/plugins/drupalimage/image.png',
           ),
    
    +++ b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalLink.php
    @@ -52,14 +53,16 @@ public function getConfig(Editor $editor) {
    +    $language_interface = \Drupal::languageManager()->getCurrentLanguage();
    +    $rtl = $language_interface->getDirection() === LanguageInterface::DIRECTION_RTL ? '_rtl' : '';
         return array(
           'DrupalLink' => array(
             'label' => t('Link'),
    -        'image' => $path . '/link.png',
    +        'image' . $rtl => $path . '/link.png',
           ),
           'DrupalUnlink' => array(
             'label' => t('Unlink'),
    -        'image' => $path . '/unlink.png',
    +        'image' . $rtl => $path . '/unlink.png',
    
    +++ b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/Internal.php
    @@ -146,48 +146,59 @@ public function getButtons() {
    +        'image_alternative_rtl' => $button('bold', 'rtl'),
    ...
    +        'image_alternative_rtl' => $button('italic', 'rtl'),
    

    I don't see why these changes are necessary?

    AFAICT you can delete all these changes and still end up with exactly the same HTML?

    In other words: I don't think these changes are necessary to fix the problem?

  2. +++ b/core/modules/ckeditor/css/ckeditor.admin.css
    @@ -182,11 +182,16 @@
    +.ckeditor-buttons li .cke_ltr {
    +    direction: ltr;
    +}
    +.ckeditor-buttons li .cke_rtl {
    +    direction: rtl;
    +}
    

    Nit: Indented with 4 instead of 2 spaces.

  3. +++ b/core/modules/ckeditor/src/Tests/CKEditorToolbarButtonTest.php
    @@ -0,0 +1,81 @@
    + * @package Drupal\ckeditor\Tests
    

    You can delete this line.

  4. +++ b/core/modules/ckeditor/src/Tests/CKEditorToolbarButtonTest.php
    @@ -0,0 +1,81 @@
    +class CKEditorToolbarButtonTest extends WebTestBase {
    +  /**
    

    Nit: needs a \n in between.

  5. +++ b/core/modules/ckeditor/src/Tests/CKEditorToolbarButtonTest.php
    @@ -0,0 +1,81 @@
    +  }
    +}
    

    Nit: needs a \n in between.

aneek’s picture

@Wim Leers, thanks for the review. I might have misses something in the patch. This should work. I will check again and update accordingly this weekend.
Thanks.

aneek’s picture

StatusFileSize
new181.17 KB
new141.76 KB
new139.84 KB

@Wim Leers,

I've tested the same you tested and I can see that the patch is working with the latest HEAD (beta). Please have a look at the attached image "before_patch" & "after_patch". Btw, have you cleared the browser cache before testing? Might have some effect.

About your query on the changes:

#5.1: Have a look at the file core/modules/ckeditor/ckeditor.admin.inc in current HEAD @ line # 73.

elseif (isset($button['image'])) {
      $value = array(
        '#theme' => 'image',
        '#uri' => $button['image' . $rtl],
        '#title' => $button['label'],
        '#prefix' => '<a href="#" role="button" title="' . $button['label'] . '" aria-label="' . $button['label'] . '"><span class="cke_button_icon">',
        '#suffix' => '</span></a>',
      );
    }

The theme_image is searching for a button with key "image_rtl" if the direction is RTL. The image buttons are coming from "Plugin/CKEditorPlugin/DrupalImage.php" & "Plugin/CKEditorPlugin/DrupalLink.php" files. In both the files getButtons() method doesn't consider the image direction. So even if the button key exists as "image" the URI is not set. So those changes were done. Have a look at the image "image_not_found.png".

The rest reviews I will address soon. Please let me know your views once you re-test the patch.

Thanks.

wim leers’s picture

#7 As my screenshots show, I tested this on simplytest.me, so I don't see how browser caches could ever cause any problems :( Did you perhaps forget to include a few small things in the patch, that you do have locally? Otherwise, I really have no idea at all how we could be seeing so vastly different things! Note I tested in Chrome.

The theme_image is searching for a button with key "image_rtl" if the direction is RTL.

Oh, LOL, how did I miss that!? I think this would be a much simpler solution then:

-    elseif (isset($button['image'])) {
+    elseif (isset($button['image' . $rtl]) || isset($button['image'])) {
       $value = array(
         '#theme' => 'image',
-        '#uri' => $button['image' . $rtl],
+        '#uri' => isset($button['image' . $rtl]) ? $button['image' . $rtl] : $button['image'],

In other words: the buttons that don't need LTR/RTL variants, can just use the much simpler $button['image']. Those that do have LTR and RTL variants can provide both $button['image_ltr'] and $button['image_rtl'].

aneek’s picture

StatusFileSize
new157.39 KB

@Wim Leers, I do agree with you about the simple solution. About the patch, no I am testing in https://simplytest.me/ not in local with the patch. Btw I am installing ARABIC language. Which language are you using? I checked in Chrome as well in Windows & Ubuntu. Both seems to work fine. Please have a look at the attached image (Chrome_LANG_AR_after_patch).

wim leers’s picture

Issue tags: -Needs manual testing

Confirmed now that it works perfectly :)

So, all that is left, is addressing the nits in points 2–5 in #5, and the simpler solution in #7.

aneek’s picture

StatusFileSize
new4.5 KB
new8.41 KB

Uploading new patch.

aneek’s picture

Status: Needs work » Needs review
wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Great work, @aneek! Thanks for your patience!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 11: 2563543-11.patch, failed testing.

Status: Needs work » Needs review

aneek queued 11: 2563543-11.patch for re-testing.

aneek’s picture

Assigned: aneek » Unassigned
Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 11: 2563543-11.patch, failed testing.

Status: Needs work » Needs review

aneek queued 11: 2563543-11.patch for re-testing.

aneek’s picture

Status: Needs review » Reviewed & tested by the community

I can't get why this fails. This may be due to other issues. Making it RTBC again. If someone finds any issues then please change the status.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 11: 2563543-11.patch, failed testing.

Status: Needs work » Needs review

aneek queued 11: 2563543-11.patch for re-testing.

aneek’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed ae70ed6 and pushed to 8.0.x. Thanks!

  • alexpott committed ae70ed6 on 8.0.x
    Issue #2563543 by aneek, Wim Leers: CKEditor Toolbar - various button...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.