Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Fix wysiwyg max character, soften the warning and add visual helper #16975

Merged
merged 2 commits into from May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions bundles/TinymceBundle/public/js/editor.js
Expand Up @@ -26,6 +26,8 @@ pimcore.bundle.tinymce.editor = Class.create({
if (e.detail.context === 'object') {
if (!isNaN(e.detail.config.maxCharacters) && e.detail.config.maxCharacters > 0) {
this.maxChars = e.detail.config.maxCharacters;
}else{
this.maxChars = -1;
}
}

Expand Down Expand Up @@ -83,6 +85,8 @@ pimcore.bundle.tinymce.editor = Class.create({
defaultConfig = pimcore[e.detail.context][subSpace].wysiwyg ? pimcore[e.detail.context][subSpace].wysiwyg.defaultEditorConfig : {};
}

const maxChars = this.maxChars;

tinymce.init(Object.assign({
selector: `#${this.textareaId}`,
height: 500,
Expand All @@ -99,9 +103,14 @@ pimcore.bundle.tinymce.editor = Class.create({
extended_valid_elements: 'a[class|name|href|target|title|pimcore_id|pimcore_type],img[class|style|longdesc|usemap|src|border|alt=|title|hspace|vspace|width|height|align|pimcore_id|pimcore_type]',
init_instance_callback: function (editor) {
editor.on('input', function (eChange) {
tinymce.activeEditor.getBody().style.border = '';
tinymce.activeEditor.getElement().setAttribute('title', '');

const charCount = tinymce.activeEditor.plugins.wordcount.body.getCharacterCount();
if (this.maxChars !== -1 && charCount > this.maxChars) {
pimcore.helpers.showNotification(t('error'), t('char_count_limit_reached'), 'error');

if (maxChars !== -1 && charCount > maxChars) {
tinymce.activeEditor.getBody().style.border = '1px solid red';
tinymce.activeEditor.getElement().setAttribute('title', t('maximum_length_is') + ' ' + maxChars);
}
document.dispatchEvent(new CustomEvent(pimcore.events.changeWysiwyg, {
detail: {
Expand Down
2 changes: 1 addition & 1 deletion bundles/TinymceBundle/translations/admin.en.yaml
@@ -1,2 +1,2 @@
error: Error
char_count_limit_reached: The character limit has been reached!
maximum_length_is: The maximum length for this field is