Skip to content

Commit

Permalink
pkp#9366 Upgrade tinymce from v5 to v6
Browse files Browse the repository at this point in the history
  • Loading branch information
blesildaramirez committed Jan 8, 2025
1 parent 4fd34f7 commit 96aca39
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 50 deletions.
2 changes: 1 addition & 1 deletion classes/components/forms/FieldRichText.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class FieldRichText extends Field
public $toolbar = 'formatgroup';

/** @var array Optional. A list of required plugins. */
public $plugins = 'paste';
public $plugins = [];

/** @var string Optional. A list of comma separated elements. */
public $invalidElements;
Expand Down
2 changes: 1 addition & 1 deletion classes/components/forms/FieldRichTextarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FieldRichTextarea extends Field
public $init;

/** @var array Optional. A list of required plugins. */
public $plugins = 'paste,link,noneditable';
public $plugins = ['link'];

/** @var string Optional. A preset size option. */
public $size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct($action, $locales, string $baseUrl, string $temporar
'isMultilingual' => true,
'size' => 'large',
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist',
'plugins' => 'paste,link,lists',
'plugins' => ['link','lists'],
]))
->addField(new FieldUploadImage('image', [
'label' => __('manager.image'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct($action, $locales, $context, $baseUrl, $temporaryFil
'isMultilingual' => true,
'value' => $context->getData('additionalHomeContent'),
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist | image | code',
'plugins' => 'paste,link,lists,image,code',
'plugins' => ['link','lists','image','code'],
'uploadUrl' => $imageUploadUrl,
]));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function __construct($action, $locales, $context, $baseUrl, $temporaryFil
'isMultilingual' => true,
'value' => $context->getData('pageFooter'),
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist | image | code',
'plugins' => 'paste,link,lists,image,code',
'plugins' => ['link','lists','image','code'],
'uploadUrl' => $imageUploadUrl,
]))
->addField(new FieldOptions('sidebar', [
Expand Down
6 changes: 3 additions & 3 deletions classes/components/forms/context/PKPInformationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct($action, $locales, $context, $imageUploadUrl)
'groupId' => 'descriptions',
'value' => $context->getData('readerInformation'),
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist | image | code',
'plugins' => 'paste,link,lists,image,code',
'plugins' => ['link','lists','image','code'],
'uploadUrl' => $imageUploadUrl,
]))
->addField(new FieldRichTextarea('authorInformation', [
Expand All @@ -58,7 +58,7 @@ public function __construct($action, $locales, $context, $imageUploadUrl)
'groupId' => 'descriptions',
'value' => $context->getData('authorInformation'),
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist | image | code',
'plugins' => 'paste,link,lists,image,code',
'plugins' => ['link','lists','image','code'],
'uploadUrl' => $imageUploadUrl,
]))
->addField(new FieldRichTextarea('librarianInformation', [
Expand All @@ -67,7 +67,7 @@ public function __construct($action, $locales, $context, $imageUploadUrl)
'groupId' => 'descriptions',
'value' => $context->getData('librarianInformation'),
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist | image | code',
'plugins' => 'paste,link,lists,image,code',
'plugins' => ['link','lists','image','code'],
'uploadUrl' => $imageUploadUrl,
]));
}
Expand Down
2 changes: 1 addition & 1 deletion classes/components/forms/context/PKPLicenseForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function __construct($action, $locales, $context)
'isMultilingual' => true,
'value' => $context->getData('licenseTerms'),
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist',
'plugins' => 'paste,link,lists',
'plugins' => ['link','lists'],
]));
}
}
4 changes: 2 additions & 2 deletions classes/components/forms/context/PKPMastheadForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function __construct($action, $locales, $context, $imageUploadUrl)
'isMultilingual' => true,
'groupId' => 'editorialMasthead',
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist | image | code',
'plugins' => 'paste,link,lists,image,code',
'plugins' => ['link','lists','image','code'],
'uploadUrl' => $imageUploadUrl,
'value' => $context->getData('editorialHistory'),
]))
Expand All @@ -116,7 +116,7 @@ public function __construct($action, $locales, $context, $imageUploadUrl)
'size' => 'large',
'groupId' => 'about',
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist | image | code',
'plugins' => 'paste,link,lists,image,code',
'plugins' => ['link','lists','image','code'],
'uploadUrl' => $imageUploadUrl,
'value' => $context->getData('about'),
]));
Expand Down
2 changes: 1 addition & 1 deletion classes/components/forms/context/PKPPrivacyForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct($action, $locales, $context, $imageUploadUrl)
'isMultilingual' => true,
'value' => $context->getData('privacyStatement'),
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist | image | code',
'plugins' => 'paste,link,lists,image,code',
'plugins' => ['link','lists','image','code'],
'uploadUrl' => $imageUploadUrl,
]));
}
Expand Down
4 changes: 2 additions & 2 deletions classes/components/forms/context/PKPReviewGuidanceForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public function __construct($action, $locales, $context)
'isMultilingual' => true,
'value' => $context->getData('reviewGuidelines'),
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist',
'plugins' => 'paste,link,lists',
'plugins' => ['link','lists'],
]))
->addField(new FieldRichTextarea('competingInterests', [
'label' => __('manager.setup.competingInterests'),
'isMultilingual' => true,
'value' => $context->getData('competingInterests'),
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist',
'plugins' => 'paste,link,lists',
'plugins' => ['link','lists'],
]))
->addField(new FieldShowEnsuringLink('showEnsuringLink', [
'options' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(string $action, array $locales)
'size' => 'large',
'isMultilingual' => true,
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist',
'plugins' => 'paste,link,lists',
'plugins' => ['link','lists'],
]));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,71 +47,71 @@ public function __construct(string $action, array $locales, Context $context)
'isMultilingual' => true,
'value' => $context->getData('authorGuidelines'),
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist',
'plugins' => 'paste,link,lists',
'plugins' => ['link','lists'],
]))
->addField(new FieldRichTextarea('beginSubmissionHelp', [
'label' => __('submission.wizard.beforeStart'),
'description' => __('manager.setup.workflow.beginSubmissionHelp.description'),
'isMultilingual' => true,
'value' => $context->getData('beginSubmissionHelp'),
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist',
'plugins' => 'paste,link,lists',
'plugins' => ['link','lists'],
]))
->addField(new FieldRichTextarea('submissionChecklist', [
'label' => __('manager.setup.submissionPreparationChecklist'),
'description' => __('manager.setup.submissionPreparationChecklistDescription'),
'isMultilingual' => true,
'value' => $context->getData('submissionChecklist'),
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist',
'plugins' => 'paste,link,lists',
'plugins' => ['link','lists'],
]))
->addField(new FieldRichTextarea('uploadFilesHelp', [
'label' => __('submission.upload.uploadFiles'),
'description' => __('manager.setup.workflow.uploadFilesHelp.description'),
'isMultilingual' => true,
'value' => $context->getData('uploadFilesHelp'),
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist',
'plugins' => 'paste,link,lists',
'plugins' => ['link','lists'],
]))
->addField(new FieldRichTextarea('contributorsHelp', [
'label' => __('publication.contributors'),
'description' => __('manager.setup.workflow.contributorsHelp.description'),
'isMultilingual' => true,
'value' => $context->getData('contributorsHelp'),
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist',
'plugins' => 'paste,link,lists',
'plugins' => ['link','lists'],
]))
->addField(new FieldRichTextarea('detailsHelp', [
'label' => __('common.details'),
'description' => __('manager.setup.workflow.detailsHelp.description'),
'isMultilingual' => true,
'value' => $context->getData('detailsHelp'),
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist',
'plugins' => 'paste,link,lists',
'plugins' => ['link','lists'],
]))
->addField(new FieldRichTextarea('forTheEditorsHelp', [
'label' => __('submission.forTheEditors'),
'description' => __('manager.setup.workflow.forTheEditorsHelp.description'),
'isMultilingual' => true,
'value' => $context->getData('forTheEditorsHelp'),
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist',
'plugins' => 'paste,link,lists',
'plugins' => ['link','lists'],
]))
->addField(new FieldRichTextarea('reviewHelp', [
'label' => __('submission.reviewAndSubmit'),
'description' => __('manager.setup.workflow.reviewHelp.description'),
'isMultilingual' => true,
'value' => $context->getData('reviewHelp'),
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist',
'plugins' => 'paste,link,lists',
'plugins' => ['link','lists'],
]))
->addField(new FieldRichTextarea('copyrightNotice', [
'label' => __('manager.setup.copyrightNotice'),
'description' => __('manager.setup.copyrightNotice.description', ['url' => $submissionUrl]),
'isMultilingual' => true,
'value' => $context->getData('copyrightNotice'),
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist',
'plugins' => 'paste,link,lists',
'plugins' => ['link','lists'],
]));
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"sokil/php-isocodes": "^4.1",
"sokil/php-isocodes-db-i18n": "^4.0",
"symfony/mailer": "^7.0",
"tinymce/tinymce": "^5.7",
"tinymce/tinymce": "6.1.0",
"wikimedia/less.php": "3.*"
},
"require-dev": {
Expand Down
30 changes: 16 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions js/classes/Handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@
if (typeof tinyMCE !== 'undefined') {
var $element = this.getHtmlElement(),
elementId = $element.attr('id'),
settings = tinyMCE.EditorManager.settings;
settings = $.pkp.controllers.SiteHandler.prototype.tinymceParams_;

settings.defaultToolbar = settings.toolbar;

Expand All @@ -701,7 +701,7 @@
icon = $('<div></div>'),
iconParent = $('<div></div>'),
classes, i, editor,
settings = tinyMCE.EditorManager.settings;
settings = $.pkp.controllers.SiteHandler.prototype.tinymceParams_;

// Set the extended toolbar, if requested
if ($(this).hasClass('extendedRichContent')) {
Expand Down
26 changes: 17 additions & 9 deletions js/controllers/SiteHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@
*/
$.pkp.controllers.SiteHandler.prototype.unsavedFormElements_ = null;

/**
* The "init" params for tinymce
* @private
* @type {Array}
*/
$.pkp.controllers.SiteHandler.prototype.tinymceParams_ = null;


//
// Public static methods.
Expand All @@ -141,8 +148,7 @@
width: '100%',
resize: 'both',
entity_encoding: 'raw',
plugins: 'paste,fullscreen,link,lists,code,' +
'image,-pkpTags,noneditable',
plugins: ['fullscreen','link','lists','code','image','-pkpTags'],
convert_urls: false,
forced_root_block: 'p',
paste_auto_cleanup_on_paste: true,
Expand All @@ -154,7 +160,8 @@
'image | pkpTags',
statusbar: false,
content_css: contentCSS,
browser_spellcheck: true
browser_spellcheck: true,
skin: 'tinymce-5'
};

// Support image uploads
Expand Down Expand Up @@ -204,6 +211,8 @@
tinymceParams.setup =
$.pkp.controllers.SiteHandler.prototype.triggerTinyMCESetup;

$.pkp.controllers.SiteHandler.prototype.tinymceParams_ = tinymceParams;

tinyMCE.init(tinymceParams);
}
};
Expand Down Expand Up @@ -237,23 +246,22 @@

// For read-only controls, set up TinyMCE read-only mode.
if (target.attr('readonly')) {
tinyMCEObject.settings.readonly = true;
$.pkp.controllers.SiteHandler.prototype.tinymceParams_.readonly = true;
}

if (target.attr('wordCount') && target.attr('wordCount') > 0) {
tinyMCEObject.settings.plugins =
tinyMCEObject.settings.plugins + ',pkpwordcount';
tinyMCEObject.settings.statusbar = true;
$.pkp.controllers.SiteHandler.prototype.tinymceParams_.plugins.push('pkpwordcount');
$.pkp.controllers.SiteHandler.prototype.tinymceParams_.statusbar = true;
}

if (target.attr('dir')) {
tinyMCEObject.settings.directionality = target.attr('dir');
$.pkp.controllers.SiteHandler.prototype.tinymceParams_.directionality = target.attr('dir');
}

// Set height based on textarea rows
height = target.attr('rows') || 10; // default: 10
height *= 20; // 20 pixels per row
tinyMCEObject.settings.height = height.toString() + 'px';
$.pkp.controllers.SiteHandler.prototype.tinymceParams_.height = height.toString() + 'px';

// Add a fake HTML5 placeholder when the editor is intitialized
tinyMCEObject.on('init', function(tinyMCEObject) {
Expand Down

0 comments on commit 96aca39

Please sign in to comment.