I tried the
hook_editor_js_settings_alter()
example and it works well for me.
While testing a contributed module's CKEditor 5 support, @anairamzap remarked:
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 setrtl
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.
The odd thing is that Drupal core never configured CKEditor 4's contentsLangDirection
. So AFAICT this can't be a regression. Unless there's some undocumented behavior in CKEditor 4 that automatically applied this; I suspect that it's really just the CKEditor 5 BiDi plugin does not set the content language direction correctly? (That was a contributed module/plugin in CKEditor 4 too:
https://www.drupal.org/project/ckeditor_bidi ā
ā so not a core bug then.)
But, Drupal core natively supports distinguishing UI language (\Drupal\Core\Language\LanguageInterface::TYPE_INTERFACE
) and content language (\Drupal\Core\Language\LanguageInterface::TYPE_CONTENT
). This cleanly maps onto CKEditor 5's capabilities.
Today, we already make sure the CKEditor 5 UI language matches Drupal's UI language, in \Drupal\ckeditor5\Plugin\Editor\CKEditor5::getJSSettings()
:
if ($this->moduleHandler->moduleExists('locale')) {
$language_interface = $this->languageManager->getCurrentLanguage();
$settings['language']['ui'] = _ckeditor5_get_langcode_mapping($language_interface->getId());
}
TBD
Add something like
if ($this->moduleHandler->moduleExists('content_translation')) {
$content_language = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT);
$settings['language']['content'] = _ckeditor5_get_langcode_mapping($content_language->getId());
}
š¤š¤ But what about multiple content languages on a single page? Does CKEditor 5 support specifying a different content language per instance? Does the editor.module
API allow for that? That seems like it'd need a follow-up.
TBD
None.
None.
TBD
Active
11.0 š„
Last updated
The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.
It denotes an issue that prevents porting of a contributed project to the stable version of Drupal due to missing APIs, regressions, and so on.
Affects the content, performance, or handling of Javascript.
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
I tried the hook_editor_js_settings_alter()
example and it works well for me.