Problem/Motivation

With D10 releasing soon with ckeditor5 this module will need to be updated

Steps to reproduce

NA

Proposed resolution

Update for ckeditor 5 maybe utilizing https://github.com/abedi-ir/ckeditor5-direction

Remaining tasks

Implement
Review
Commit

User interface changes

NA

API changes

NA

Data model changes

NA

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

smustgrave created an issue. See original summary.

wim leers’s picture

Asked the CKEditor team for guidance.

anairamzap’s picture

StatusFileSize
new106.68 KB
new10.82 KB

We are using this module on a project that is in arabic, hence the ckeditor needs to support "rtl" direction, we also are defaulting to "rtl" while showing both directions in the ckeditor toolbar.

I've tested the MR!1 by:

  1. Enabling the "CKEditor 5" experimental core module
  2. In /admin/config/content/formats choose a format and configured to use the "CKEditor 5" in the Text Editor dropdown field
  3. After clearing cache I was able to see the new button for the paragraph direction, and I added it to the "Active toolbar"
  4. UPDATE:
    Only one really minor issue in here: the styling for the button seems to be a bit broken (showing like a dropdown arrow above the icon). It should be a really quick fix to maybe remove it on .ckeditor5-toolbar-button-direction::after on bidi_direction.admin.css line 22
    Please disregard this, I was not using Claro theme to test this :S. On Claro there are no issues with the button in the config page:
    Only local images are allowed.
  5. Saved changes in the text format. No errors or issues to report.
  6. Finally I've created a new node, and I was able to use the BIDI button to set the paragraphs direction. No errors.
    BIDI button paragraph dir

The only thing missing to behave exactly as is CK4 is not related with this plugin/module, but with the contentsLangDirection https://docs-old.ckeditor.com/ckeditor_api/symbols/CKEDITOR.config.html#... that we were using to set rtl as the default direction. Just commenting this here in case it helps someone else for the upgrade: https://ckeditor.com/docs/ckeditor5/latest/installation/getting-started/...
UPDATE: to set the default language/direction in CK5 you can use the following hook:

/**
 * Implements hook_editor_js_settings_alter.
 */
function module_name_editor_js_settings_alter(array &$settings) {
  foreach ($settings['editor']['formats'] as $name => $value) {
    $settings['editor']['formats'][$name]['editorSettings']['language'] = [
      'ui' => 'en',
      'content' => 'ar'
    ];
  }
}

That uses the language config for CK5 API and sets a different lang for the UI and the editor content for all editor formats.

wim leers’s picture

The only thing missing to behave exactly as is CK4 is not related with this plugin/module, but with the contentsLangDirection https://docs-old.ckeditor.com/ckeditor_api/symbols/CKEDITOR.config.html#... that we were using to set rtl as the default direction. Just commenting this here in case it helps someone else for the upgrade: https://ckeditor.com/docs/ckeditor5/latest/installation/getting-started/...
UPDATE: to set the default language/direction in CK5 you can use the following hook:

/**
 * Implements hook_editor_js_settings_alter.
 */
function module_name_editor_js_settings_alter(array &$settings) {
  foreach ($settings['editor']['formats'] as $name => $value) {
    $settings['editor']['formats'][$name]['editorSettings']['language'] = [
      'ui' => 'en',
      'content' => 'ar'
    ];
  }
}

That uses the language config for CK5 API and sets a different lang for the UI and the editor content for all editor formats.

Woah! WHAT A FIND! Extracted into a Drupal core issue, thank you! 🙏 See #3312816: CKEditor 5 should explicitly set negotiated content language, not just UI language — credited you!

wim leers’s picture

Actually … isn't this already covered by the Language toolbar item in core, which uses the language.TextPartLanguage CKEditor 5 plugin?

Tested it and … looks like the difference is that that plugin can only produce

<p>
    <span lang="ar" dir="rtl">asdf;sladkfjadsf;lkasdfj</span>
</p>

whereas the BiDi plugin can produce

<p lang="ar" dir="rtl">
    asdf;sladkfjadsf;lkasdfj
</p>

So close, so unfortunate! 😬 We could've hugely simplified all this otherwise! 😞

smustgrave’s picture

So are you staying we may not need this module? Should the language button be updated to allow for a default language? and apply to p tags.

wim leers’s picture

So are you staying we may not need this module? Should the language button be updated to allow for a default language? and apply to p tags.

Sadly, no, because of the "so close, so unfortunate" bit 😞

smustgrave’s picture

Status: Active » Needs review

Personally I prefer the approach of using one button but lets see.

wim leers’s picture

wim leers’s picture

  • The current merge request removes the CKEditor 4 plugin. That's bad: it means that the existing text editors using CKEditor 4 will immediately be broken upon installing this version of the module! It's very strongly recommended to support both CKEditor versions simultaneously.
  • Because of 👆, it actually was impossible to write a upgrade path completeness test too!

In working on the upgrade path test coverage, I ran into two core bugs: #3314478: Follow-up for #3231334: global attributes should result in HTMLRestrictions becoming simplified and #3314511: CKEditor 4 → 5 upgrade path may trigger warnings in some edge cases, making upgrade path tests impossible! This is blocked on the first only (it'll make the second disappear).

Until that core bug is fixed, this will fail with:

1) Drupal\Tests\ckeditor_bidi\Kernel\UpgradePathTest::test with data set "both CKEditor 4 buttons" ('ckeditor_bidi_both', array(), array(array(array('bold', 'heading', '|', 'direction')), array(array(array('heading2', 'heading3')), array(false))), '', array(), array(), array())
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-''
+'<p dir="ltr rtl"> <h2 dir="ltr rtl"> <h3 dir="ltr rtl">'

But already without that core patch applied, you'll see one test failure:

1) Drupal\Tests\ckeditor_bidi\Kernel\UpgradePathTest::test with data set "LTR CKEditor 4 button only" ('ckeditor_bidi_ltr_only', array(), array(array(array('bold', 'heading', '|', 'direction')), array(array(array('heading2', 'heading3')), array(false))), '', array(), array(), array())
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
         'items' => Array &2 (
             0 => 'bold'
             1 => 'heading'
-            2 => '|'
-            3 => 'direction'
         )
     )
     'plugins' => Array &3 (
@@ @@
                 0 => 'heading2'
                 1 => 'heading3'
             )
-        )
-        'ckeditor_bidi_ckeditor5' => Array &6 (
-            'rtl_default' => false
         )
     )
 )

(I've already left a comment on the MR where I point out the root cause.)

smustgrave’s picture

Added the ckeditor4 plugin back.

Addressed most of the open threads though a few questions.

Other one is how do we setup translations?

wim leers’s picture

Yay, the upgrade path test now passes! (With #3314478: Follow-up for #3231334: global attributes should result in HTMLRestrictions becoming simplified applied to Drupal core.)

Other one is how do we setup translations?

Created #3314680: Incorporate translations support into the starter template for that. Not sure either, I have barely worked on the JS side of CKEditor 5!

I think that for now, you can choose to not handle translations. Or, if you modify the plugin further, you could choose to use Drupal.t()

wim leers’s picture

Good news: per https://softwareengineering.stackexchange.com/a/105926 (and per @lauriii!), you can in fact relicense MIT under the GPL. You just have to include the original license file.
This also means that you can easily handle translations in this case by adding Drupal.t() calls 👍

smustgrave’s picture

Resolved most of the points. but left a few questions on others

RTBC = #3314478: Follow-up for #3231334: global attributes should result in HTMLRestrictions becoming simplified

wim leers’s picture

Title: [PP-1] Make ready for CKEditor 5 » Make ready for CKEditor 5
Status: Postponed » Needs review
wim leers’s picture

Status: Needs review » Needs work

Posted another review round! 👍

This is getting very close to the finish line! 🤩

smustgrave’s picture

Status: Needs work » Needs review

Addressed what I could. Left comments on the threads I had questions on.

Thanks!

wim leers’s picture

Title: Make ready for CKEditor 5 » [PP-1] Make ready for CKEditor 5
wim leers’s picture

Title: [PP-1] Make ready for CKEditor 5 » [PP-2] Make ready for CKEditor 5

Actually, two issues are blocking this, thanks to @smustgrave confirming that on the merge request. #3312816: CKEditor 5 should explicitly set negotiated content language, not just UI language is the second.

wim leers’s picture

Title: [PP-2] Make ready for CKEditor 5 » [PP-1] Make ready for CKEditor 5
smustgrave’s picture

@Wim Leers what's left for this issue?

wim leers’s picture

Per #23, AFAICT the only blocker to this working is #3312816: CKEditor 5 should explicitly set negotiated content language, not just UI language. If you could push that forward, I would be eligible to RTBC 😇🙏

smustgrave’s picture

Unfortunately don't know what the fix is for https://www.drupal.org/project/drupal/issues/3312816. Not entirely sure I even understand the issue.

smustgrave’s picture

So still confused how https://www.drupal.org/project/drupal/issues/3312816 blocks this.

This module sets rtl but NO lang so sounds like that’s missing.

But adding to core not sure if it fixes here

They seem independent of each other

smustgrave’s picture

Status: Needs review » Fixed
smustgrave’s picture

Status: Fixed » Closed (fixed)

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