Skip to content
Snippets Groups Projects
Commit 969c2a9e authored by Georg Ringer's avatar Georg Ringer
Browse files

[FEATURE] Set content language direction in RichText elements

Set the content language of RichText elements based on the direction
of the site language of the given element.

Resolves: #97778
Releases: main
Change-Id: Iaf95886d82a417df5e9149d0d3296baaf6fb3b9c
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74966


Tested-by: default avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: default avatarcore-ci <typo3@b13.com>
Tested-by: default avatarGuido Schmechel <guido.schmechel@brandung.de>
Tested-by: default avatarGeorg Ringer <georg.ringer@gmail.com>
Reviewed-by: default avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: default avatarGuido Schmechel <guido.schmechel@brandung.de>
Reviewed-by: default avatarOliver Hader <oliver.hader@typo3.org>
Reviewed-by: default avatarGeorg Ringer <georg.ringer@gmail.com>
parent d868873c
Branches
Tags
No related merge requests found
......@@ -61,6 +61,7 @@ class DatabaseSystemLanguageRows implements FormDataProviderInterface
'title' => $language->getTitle(),
'iso' => $iso,
'flagIconIdentifier' => $language->getFlagIdentifier(),
'direction' => $language->getDirection(),
];
if (empty($iso)) {
......
......@@ -59,15 +59,18 @@ class DatabaseSystemLanguageRowsTest extends UnitTestCase
$siteLanguageMinusOne->getLanguageId()->willReturn(-1);
$siteLanguageMinusOne->getTitle()->willReturn('All');
$siteLanguageMinusOne->getFlagIdentifier()->willReturn('flags-multiple');
$siteLanguageMinusOne->getDirection()->willReturn('');
$siteLanguageZero = $this->prophesize(SiteLanguage::class);
$siteLanguageZero->getLanguageId()->willReturn(0);
$siteLanguageZero->getTitle()->willReturn('English');
$siteLanguageZero->getFlagIdentifier()->willReturn('empty-empty');
$siteLanguageZero->getDirection()->willReturn('ltr');
$siteLanguageOne = $this->prophesize(SiteLanguage::class);
$siteLanguageOne->getLanguageId()->willReturn(1);
$siteLanguageOne->getTitle()->willReturn('Dutch');
$siteLanguageOne->getFlagIdentifier()->willReturn('flag-nl');
$siteLanguageOne->getTwoLetterIsoCode()->willReturn('NL');
$siteLanguageOne->getDirection()->willReturn('rtl');
$siteLanguages = [
$siteLanguageMinusOne->reveal(),
$siteLanguageZero->reveal(),
......@@ -85,18 +88,21 @@ class DatabaseSystemLanguageRowsTest extends UnitTestCase
'title' => 'All',
'iso' => 'DEF',
'flagIconIdentifier' => 'flags-multiple',
'direction' => '',
],
0 => [
'uid' => 0,
'title' => 'English',
'iso' => 'DEF',
'flagIconIdentifier' => 'empty-empty',
'direction' => 'ltr',
],
1 => [
'uid' => 1,
'title' => 'Dutch',
'iso' => 'NL',
'flagIconIdentifier' => 'flag-nl',
'direction' => 'rtl',
],
],
];
......
.. include:: /Includes.rst.txt
.. _feature-97778-1655732248:
===========================================================
Feature: #97778 - Support of language direction in ckeditor
===========================================================
See :issue:`97778`
Description
===========
The configuration `contentsLangDirection` of the ckeditor is used to define the
direction of the content. It is now filled by the direction defined in the site
language of the current element.
As fallback the Page TsConfig configuration :typoscript:`RTE.config.contentsLanguageDirection = rtl`
can be used.
Impact
======
The direction of the content inside the RichText element is defined by the
language of record.
.. index:: Backend, RTE, ext:rte_ckeditor
......@@ -195,6 +195,19 @@ class RichTextElement extends AbstractFormElement
return $contentLanguage;
}
/**
* Determine the language direction
*/
protected function getLanguageDirectionOfContent(): string
{
$currentLanguageUid = ($this->data['databaseRow']['sys_language_uid'] ?? 0);
if (is_array($currentLanguageUid)) {
$currentLanguageUid = $currentLanguageUid[0];
}
$contentLanguageUid = (int)max($currentLanguageUid, 0);
return $this->data['systemLanguageRows'][$contentLanguageUid]['direction'] ?? '';
}
/**
* Gets the JavaScript code for CKEditor module
* Compiles the configuration, and then adds plugins
......@@ -364,6 +377,7 @@ class RichTextElement extends AbstractFormElement
$configuration['language'] = $userLang === 'default' ? 'en' : $userLang;
}
$configuration['contentsLanguage'] = $this->getLanguageIsoCodeOfContent();
$configuration['contentsLangDirection'] = $this->getLanguageDirectionOfContent();
// Replace all label references
$configuration = $this->replaceLanguageFileReferences($configuration);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment