Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Resolves #55
Resolves #33
  • Loading branch information
brandonkelly committed Dec 16, 2022
2 parents 6cf5eac + 5a752d0 commit dd8fa42
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# Release Notes for CKEditor for Craft CMS

## Unreleased
- Added RTL language support. ([#33](https://github.com/craftcms/ckeditor/issues/33), [#55](https://github.com/craftcms/ckeditor/pull/55))

## 2.0.0 - 2022-05-03

### Added
- Added Craft 4 compatibility

## 1.4.0 - 2022-12-16
- Added RTL language support. ([#33](https://github.com/craftcms/ckeditor/issues/33), [#55](https://github.com/craftcms/ckeditor/pull/55))

## 1.3.0 - 2022-02-11

### Changed
Expand Down
30 changes: 25 additions & 5 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,35 @@ protected function inputHtml(mixed $value, ElementInterface $element = null): st
$view->registerJsFile(Plugin::getInstance()->getBuildUrl());
$view->registerAssetBundle(FieldAsset::class);

$language = Json::encode(mb_strtolower(Craft::$app->language));
$appLanguage = mb_strtolower(Craft::$app->language);
$language = Json::encode($appLanguage); // for v4
$filebrowserBrowseUrl = Json::encode($this->availableVolumes ? UrlHelper::actionUrl('ckeditor/assets/browse', [
'fieldId' => $this->id,
]) : null);
]) : null); // for v4
$filebrowserImageBrowseUrl = Json::encode($this->availableVolumes ? UrlHelper::actionUrl('ckeditor/assets/browse', [
'fieldId' => $this->id,
'kind' => Asset::KIND_IMAGE,
]) : null);
]) : null); // for v4
$langClass = ''; // for v4, ignored in v5

// Explicitly set the text direction
$contentsLangDirection = Json::encode("ltr"); // for v4
$v5language = Json::encode($appLanguage); // for v5

if ($this->translationMethod != self::TRANSLATION_METHOD_NONE) {
$elementSite = ($element ? $element->getSite() : Craft::$app->getSites()->getCurrentSite());
$contentLocale = Craft::$app->getI18n()->getLocaleById($elementSite->language);

$langClass = ' cke_' . $contentLocale->getOrientation();
$contentsLangDirection = Json::encode($contentLocale->getOrientation()); // for v4
$v5language = Json::encode($contentLocale->id); // for v5
}

$js = <<<JS
const language = $language;
const filebrowserBrowseUrl = $filebrowserBrowseUrl;
const filebrowserImageBrowseUrl = $filebrowserImageBrowseUrl;
const contentsLangDirection = $contentsLangDirection;
JS;

Expand All @@ -166,6 +182,7 @@ protected function inputHtml(mixed $value, ElementInterface $element = null): st
language,
filebrowserBrowseUrl,
filebrowserImageBrowseUrl,
contentsLangDirection,
});
} else {
// CKEditor 5
Expand All @@ -186,7 +203,10 @@ protected function inputHtml(mixed $value, ElementInterface $element = null): st
}
return await editorClass
.create(document.querySelector('#__EDITOR__'), {
language,
language: {
ui: $v5language,
content: $v5language,
}
});
}
JS;
Expand All @@ -200,7 +220,7 @@ protected function inputHtml(mixed $value, ElementInterface $element = null): st
Html::textarea($this->handle, $this->prepValueForInput($value, $element), [
'id' => $id,
]), [
'class' => 'readable',
'class' => 'readable' . $langClass,
]);
}

Expand Down

0 comments on commit dd8fa42

Please sign in to comment.