Skip to content

fix: Adding text-enabled plugins failed after adding first plugin #91

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

Merged
merged 4 commits into from
May 23, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Changelog
=========

0.8.6 (23-05-2025)
==================

* fix: Adding text-enabled plugins failed after adding first plugin by @fsbraun in https://github.com/django-cms/djangocms-text/pull/91
* fix: Crashed if `STATIC_URL` was not set by @fsbraun

0.8.5 (15-05-2025)
==================

Expand Down
31 changes: 30 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ from djangocms-text-ckeditor, and clean up old tables. All you have to do is:
* add ``djangocms_text`` to ``INSTALLED_APPS`` (see above)
* run ``python -m manage migrate djangocms_text``

**Attention**: The migration command also deletes djangocms-text-ckeditor's
**Attention**: The migration command also deletes djangocms-text-ckeditor's
tables from the database (to avoid referential integrity issues). To be on
the safe side, make a backup of its content.

Expand Down Expand Up @@ -156,7 +156,36 @@ Example::

TEXT_EDITOR = "djangocms_text.contrib.text_ckeditor4.ckeditor4"

Rich text editor configuration
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The ``TEXT_EDITOR`` setting points to a ``RTEConfig`` object. You can create your custom
``RTEConfig`` instance. The following attributes are available:

- name (str): The name of the RTE configuration.
- config (str): The configuration string.
- js (Iterable[str]): An iterable of JavaScript files to include.
- css (dict): A dictionary of CSS files to include.
- admin_css (Iterable[str]): An iterable of CSS files for the admin interface only.
- inline_editing (bool): Whether to enable inline editing.
- child_plugin_support (bool): Whether to support child plugins.

The default configuration is:

.. code-block:: python

RTEConfig(
name="tiptap",
config="TIPTAP",
js=("djangocms_text/bundles/bundle.tiptap.min.js",),
css={"all": ("djangocms_text/css/bundle.tiptap.min.css",)},
admin_css=("djangocms_text/css/tiptap.admin.css",),
inline_editing=True,
child_plugin_support=True,
)

You can use the ``admin_css`` attribute to include CSS files that you need to be loaded into the
dialog window, e.g., to declare custom colors or other styles.

Inline editing feature
~~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion djangocms_text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
10. Github actions will publish the new package to pypi
"""

__version__ = "0.8.5"
__version__ = "0.8.6"
6 changes: 6 additions & 0 deletions djangocms_text/editors.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,18 @@ class RTEConfig:
config (str): The configuration string.
js (Iterable[str]): An iterable of JavaScript files to include.
css (dict): A dictionary of CSS files to include.
admin_css (Iterable[str]): An iterable of CSS files for the admin interface only.
inline_editing (bool): Whether to enable inline editing.
child_plugin_support (bool): Whether to support child plugins.

Attributes:
name (str): The name of the RTE configuration.
config (str): The configuration string.
js (Iterable[str]): An iterable of JavaScript files to include.
css (dict): A dictionary of CSS files to include.
admin_css (Iterable[str]): An iterable of CSS files for the admin interface only.
inline_editing (bool): Whether to enable inline editing.
child_plugin_support (bool): Whether to support child plugins.
"""

def __init__(
Expand Down
10 changes: 4 additions & 6 deletions private/js/cms.editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ class CMSEditor {
cms_history: 0,
};
const url = `${settings.add_plugin_url}?${new URLSearchParams(data).toString()}`;
return this.loadForm(url, iframe, el, onLoad, onSave);
return this.loadPluginForm(url, iframe, el, onLoad, onSave);
}

// CMS Editor: addPluginForm
Expand All @@ -535,10 +535,10 @@ class CMSEditor {
cms_history: 0,
};
url = `${url}?${new URLSearchParams(data).toString()}`;
return this.loadForm(url, iframe, el, onLoad, onSave);
return this.loadPluginForm(url, iframe, el, onLoad, onSave);
}

loadForm (url, iframe, el, onLoad, onSave) {
loadPluginForm (url, iframe, el, onLoad, onSave) {
iframe.addEventListener('load', () => {
const form = iframe.contentDocument;
const heading = form.querySelector('#content h1');
Expand All @@ -565,9 +565,7 @@ class CMSEditor {
// Hook into the django CMS dataBridge to get the details of the newly created or saved
// plugin. For new plugins we need their id to get the content.

if (!this.CMS.API.Helpers.dataBridge) {
this.processDataBridge(form);
}
this.processDataBridge(form);
// Needed to update StructureBoard
if (onSave && this.CMS.API.Helpers.dataBridge) {
onSave(el, form, this.CMS.API.Helpers.dataBridge);
Expand Down
2 changes: 1 addition & 1 deletion tests/js/cms.editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('CMSEditor', () => {
const el = document.getElementById('editor1');
document.body.appendChild(iframe);

editor.loadForm('about:blank', iframe, el, () => {
editor.loadPluginForm('about:blank', iframe, el, () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Test should cover the multi-plugin scenario described in the bug.

Please add a test that adds a plugin, then adds a second one, to verify that loadPluginForm and processDataBridge handle multiple plugins as described in bug #90.

expect(iframe.contentDocument).toBeTruthy();
done();
});
Expand Down