Skip to content

Commit

Permalink
“Text part language” feature
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Aug 14, 2023
1 parent 1950eb2 commit d344830
Show file tree
Hide file tree
Showing 57 changed files with 656 additions and 18,410 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Added the “Word Limit” field setting. ([#107](https://github.com/craftcms/ckeditor/issues/107))
- Added the “List Plugin” CKEditor config setting. ([#112](https://github.com/craftcms/ckeditor/issues/112), [#122](https://github.com/craftcms/ckeditor/pull/122))
- Added the [Text part language](https://ckeditor.com/docs/ckeditor5/latest/features/language.html) feature.
- Added keyboard shortcuts for switching the heading type for a given block. ([#106](https://github.com/craftcms/ckeditor/issues/106), [#116](https://github.com/craftcms/ckeditor/pull/116))
- CKEditor config edit pages now have a “Save and continue editing” alternative submit action, and the <kbd>Command</kbd>/<kbd>Ctrl</kbd> + <kbd>S</kbd> keyboard shortcut now redirects back to the edit page. ([#108](https://github.com/craftcms/ckeditor/discussions/108))
- CKEditor config edit pages now have a “Save as a new config” alternative submit action. ([#110](https://github.com/craftcms/ckeditor/discussions/110))
Expand Down
17,884 changes: 47 additions & 17,837 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@ckeditor/ckeditor5-image": ">=39.0.1",
"@ckeditor/ckeditor5-indent": ">=39.0.1",
"@ckeditor/ckeditor5-inspector": ">=4.1.0",
"@ckeditor/ckeditor5-language": "^39.0.1",
"@ckeditor/ckeditor5-link": ">=39.0.1",
"@ckeditor/ckeditor5-list": ">=39.0.1",
"@ckeditor/ckeditor5-media-embed": ">=39.0.1",
Expand Down
32 changes: 28 additions & 4 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use craft\htmlfield\events\ModifyPurifierConfigEvent;
use craft\htmlfield\HtmlField;
use craft\htmlfield\HtmlFieldData;
use craft\i18n\Locale;
use craft\models\CategoryGroup;
use craft\models\ImageTransform;
use craft\models\Section;
Expand Down Expand Up @@ -80,6 +81,24 @@ public static function displayName(): string
return 'CKEditor';
}

/**
* @return array Returns the default `language.textPartLanguage` config option that should be used.
* @since 3.5.0
* @see https://ckeditor.com/docs/ckeditor5/latest/api/module_core_editor_editorconfig-LanguageConfig.html#member-textPartLanguage
*/
public static function textPartLanguage(): array
{
return Collection::make(Craft::$app->getI18n()->getSiteLocales())
->map(fn(Locale $locale) => array_filter([
'title' => $locale->getDisplayName(Craft::$app->language),
'languageCode' => $locale->id,
'textDirection' => $locale->getOrientation() === 'rtl' ? 'rtl' : null,
]))
->sortBy('title')
->values()
->all();
}

/**
* @var string|null The CKEditor config UUID
* @since 3.0.0
Expand Down Expand Up @@ -314,10 +333,6 @@ protected function inputHtml(mixed $value, ElementInterface $element = null): st
'imageTextAlternative',
],
],
'language' => [
'ui' => BaseCkeditorPackageAsset::uiLanguage(),
'content' => $element?->getSite()->language ?? Craft::$app->language,
],
'linkOptions' => $this->_linkOptions($element),
'table' => [
'contentToolbar' => [
Expand Down Expand Up @@ -362,6 +377,11 @@ protected function inputHtml(mixed $value, ElementInterface $element = null): st

$baseConfigJs = Json::encode($event->baseConfig);
$toolbarJs = Json::encode($toolbar);
$languageJs = Json::encode([
'ui' => BaseCkeditorPackageAsset::uiLanguage(),
'content' => $element?->getSite()->language ?? Craft::$app->language,
'textPartLanguage' => static::textPartLanguage(),
]);
$listPluginJs = Json::encode($ckeConfig->listPlugin);
$showWordCountJs = Json::encode($this->showWordCount);
$wordLimitJs = $this->wordLimit ?: 0;
Expand All @@ -373,6 +393,10 @@ protected function inputHtml(mixed $value, ElementInterface $element = null): st
config.toolbar = {};
}
config.toolbar.items = $toolbarJs;
if (!jQuery.isPlainObject(config.language)) {
config.language = {};
}
config.language = Object.assign($languageJs, config.language);
const extraRemovePlugins = [];
if ($showWordCountJs) {
if (typeof config.wordCount === 'undefined') {
Expand Down
Loading

0 comments on commit d344830

Please sign in to comment.