Skip to content

feat: Add CKEDITOR_BASEPATH configuration for CKEditor 4 #94

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 14 commits into from
May 28, 2025

Conversation

fsbraun
Copy link
Member

@fsbraun fsbraun commented May 27, 2025

Summary by Sourcery

Introduce support for customizing the base path of CKEditor 4 by adding a new TEXT_CKEDITOR_BASE_PATH setting and passing it through additional_context to the frontend; refactor RTEConfig to support this context and remove an obsolete template.

New Features:

  • Allow configuring CKEditor 4 base path via the TEXT_CKEDITOR_BASE_PATH setting.
  • Add basepath.js script to initialize CKEDITOR_BASEPATH in the browser.

Enhancements:

  • Extend RTEConfig to accept an additional_context dict and store it.
  • Include additional_context values (CKEDITOR_BASEPATH) in the widget’s global settings.

Chores:

  • Remove unused text_plugin_change_formx.html template.

Copy link
Contributor

sourcery-ai bot commented May 27, 2025

Reviewer's Guide

This PR introduces a configurable CKEDITOR_BASEPATH for CKEditor 4 by extending RTEConfig to accept additional_context values (pulled from Django settings or static files), wiring that context through to both the editor initialization and a small basepath loader script; it also updates the CMSEditor JS API (renaming loadForm→loadPluginForm and simplifying dataBridge handling), merges additional_context into widget global settings, and includes version bump, test adjustments, and cleanup of an obsolete template.

Sequence Diagram for CMSEditor loadPluginForm Interaction

sequenceDiagram
    participant Caller
    participant Editor as CMSEditor
    participant IFrame
    participant PluginFormDoc as Plugin Form Document

    Caller->>Editor: invoke method like addPlugin() or addPluginForm()
    activate Editor
    Editor->>Editor: Internally calls loadPluginForm(url, iframe, el, onLoad, onSave)
    Editor->>IFrame: Set src = url_with_params (to load plugin form)
    deactivate Editor

    IFrame-->>Editor: 'load' event triggered (form loaded)
    activate Editor
    Editor->>PluginFormDoc: Access document (form) from IFrame
    Editor->>Editor: this.processDataBridge(PluginFormDoc) // Called unconditionally
    opt onSave callback provided AND CMS.API.Helpers.dataBridge exists
        Editor->>Caller: onSave(el, PluginFormDoc, CMS.API.Helpers.dataBridge)
    end
    deactivate Editor
Loading

Updated Class Diagram for RTEConfig

classDiagram
    class RTEConfig {
        +name: str
        +config: str
        +js: Iterable~str~
        +css: dict
        +admin_css: Iterable~str~
        +inline_editing: bool
        +child_plugin_support: bool
        +additional_context: dict
        +__init__(name, config, js, css, admin_css, inline_editing, child_plugin_support, additional_context: dict | None)
        +process_base_config(base_config: dict) dict
    }
Loading

Updated Class Diagram for CMSEditor (JavaScript)

classDiagram
    class CMSEditor {
        <<JavaScript Class>>
        +addPlugin(placeholder_id, plugin_type, plugin_language, parent_plugin_id, el, onLoad, onSave)
        +addPluginForm(url, iframe, el, onLoad, onSave)
        -loadForm(url, iframe, el, onLoad, onSave) // Method removed
        +loadPluginForm(url, iframe, el, onLoad, onSave) // Method added (replaces loadForm)
    }
Loading

File-Level Changes

Change Details Files
Expose CKEDITOR_BASEPATH via settings and static loader
  • Import settings, static, and lazy in text_ckeditor4 init
  • Append basepath.js to editor’s JS bundle
  • Add additional_context extracting TEXT_CKEDITOR_BASE_PATH or default path
  • Create basepath.js to assign window.CKEDITOR_BASEPATH
djangocms_text/contrib/text_ckeditor4/__init__.py
djangocms_text/contrib/text_ckeditor4/static/djangocms_text/js/basepath.js
Extend RTEConfig to carry additional context
  • Update docstring to list additional_context
  • Add additional_context parameter to init
  • Initialize self.additional_context from passed dict or empty
djangocms_text/editors.py
Refactor CMSEditor’s plugin form loading
  • Rename loadForm to loadPluginForm
  • Update addPluginForm calls to use loadPluginForm
  • Remove conditional around processDataBridge, always invoke it
private/js/cms.editor.js
tests/js/cms.editor.test.js
Merge additional_context into widget settings
  • Retrieve editor_config in get_global_settings
  • Spread editor_config.additional_context into global settings dict
djangocms_text/widgets.py
Bump package version and clean up
  • Increase version to 0.8.6
  • Remove obsolete text_plugin_change_formx.html template
  • Update README and CHANGELOG placeholders
djangocms_text/__init__.py
djangocms_text/templates/cms/plugins/text_plugin_change_formx.html
CHANGELOG.rst
README.rst

Possibly linked issues

  • #123: The PR adds configuration and explicit setting for CKEDITOR_BASEPATH, fixing auto-detection with ManifestStaticFilesStorage.
  • #123: The PR adds a CKEDITOR_BASEPATH setting allowing users to correct the ckeditor.js path, fixing the 404.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @fsbraun - I've reviewed your changes - here's some feedback:

  • Remove the debugging print(toolbar_setting) left in get_global_settings to avoid console pollution.
  • Fix the typo in the RTEConfig docstring/parameter name (additonal_context should be additional_context).
  • Ensure the new additional_context is merged inside RTEConfig.process_base_config so it’s actually applied during editor initialization.
Here's what I looked at during the review
  • 🟡 General issues: 4 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

codecov bot commented May 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.86%. Comparing base (df1b635) to head (23c58bd).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #94      +/-   ##
==========================================
+ Coverage   81.61%   81.86%   +0.25%     
==========================================
  Files          14       14              
  Lines         941      954      +13     
  Branches      110      110              
==========================================
+ Hits          768      781      +13     
  Misses        130      130              
  Partials       43       43              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

fsbraun and others added 6 commits May 27, 2025 18:58
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@stefanw
Copy link
Contributor

stefanw commented May 28, 2025

I tried this out and it's almost there :)

The problem is that basepath.js gets embedded in the head of the admin edit-plugin HTML and executed immediately before the "cms-editor-cfg"' script is available later in the body. The setting of window.CKEDITOR_BASEPATH can also not be deferred to window.onload or similar as ckeditor is executed right after in the head.

Here's an alternative: setting the path as a data attribute on the script tag and then reading/setting it in the script:

stefanw@6296e77

PR #95 for your convenience and consideration.

This makes use of paths as objects available since Django 4.1..

@fsbraun fsbraun merged commit d65789b into main May 28, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants