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

Allow TinyMCE to be used in inline-mode #3465

Closed
pbauer opened this issue Mar 26, 2022 · 6 comments · Fixed by #3501
Closed

Allow TinyMCE to be used in inline-mode #3465

pbauer opened this issue Mar 26, 2022 · 6 comments · Fixed by #3501
Assignees
Labels
04 type: enhancement 99 tag: bssp Potential task for the Buschenschanksprint
Milestone

Comments

@pbauer
Copy link
Member

pbauer commented Mar 26, 2022

Inline-mode of TinyMCE (https://www.tiny.cloud/docs/demo/inline) is nice among other reasons because the edited text looks exactly the way as the saved result.

To enable it you could simply set {"inline": "true"} as the value in the field "Other settings" of the TinyMCE controlpanel. That is enough to trigger it.

But that fails with Could not initialize inline editor on invalid inline target element since the html-tag that renders the TinyMCE is a <textarea>. See https://www.tiny.cloud/blog/tinymce-inline-option-not-working for details about that constraint.

The <textarea> thing is defined in plone.app.z3cform.widget.RichTextWidget which has TextareaWidget as _base. In render_input_mode of the widget it is possible to conditionally render a different html element like div around the text. But then fallback to textarea no longer works and saving also fails and and and...

So it seems that using inline-mode in not straightforward. The question is do we like that option enough to do the required work?

@thet
Copy link
Member

thet commented Mar 30, 2022

For reference, in Plone 5 you can activate inline editing like so:

from plone.app.textfield import RichText
from plone.app.z3cform.widget import RichTextWidget
from plone.autoform.directives import widget

[...]

    # inline: True necessary for reordering rows, otherwise tinymce would not render correctly.
    # tiny config to reduce UI
    widget("description", RichTextWidget, pattern_options={
        "inline": True,
        "tiny": {
            "toolbar": "bold italic bullist unlink plonelink",
            "plugins": ["plonelink", "lists", ],
            "menubar": "",
        },
    })
    # RichText for TinyMCE
    # allowed_mime_types to not get the mimetype selector and for tinymce to actually work.
    # the mimetypeselector has a config for the textfield, but here we are cloning textfields and the mimetypeselector config isn't updated.
    description = RichText(title=u"Beschreibung", required=False, allowed_mime_types=["text/html"])

@pbauer
Copy link
Member Author

pbauer commented Apr 13, 2022

With the current solution you can globally enable or disable inline mode in the TinyMCE controlpanel and still disable or enable it by schema-field for specific types or behaviors using pattern_options={"inline": True} like the example from @thet

What I did not see earlier is that the tinymce-pattern actually uses this setting to replace the textarea with a div before instanciating tinymce. So no changes to RichTextWidget are required.

@pbauer
Copy link
Member Author

pbauer commented Apr 13, 2022

Tests are green.

@pbauer pbauer self-assigned this Apr 13, 2022
mister-roboto pushed a commit to plone/buildout.coredev that referenced this issue Apr 13, 2022
Branch: refs/heads/main
Date: 2022-04-13T10:26:48+02:00
Author: Philip Bauer (pbauer) <bauer@starzel.de>
Commit: plone/plone.base@a93dc62

Add inline mode to tinymce config (see plone/Products.CMFPlone#3465)

Files changed:
M src/plone/base/interfaces/controlpanel.py
Repository: plone.base

Branch: refs/heads/main
Date: 2022-04-13T10:29:27+02:00
Author: Philip Bauer (pbauer) <bauer@starzel.de>
Commit: plone/plone.base@f1d412f

add changenote

Files changed:
A news/7.feature
Repository: plone.base

Branch: refs/heads/main
Date: 2022-04-13T12:27:04+02:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.base@d22ddbd

Merge pull request #7 from plone/tiny_inline_mode

Add inline mode to tinymce config

Files changed:
A news/7.feature
M src/plone/base/interfaces/controlpanel.py
@mauritsvanrees
Copy link
Member

Alles gemerget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
04 type: enhancement 99 tag: bssp Potential task for the Buschenschanksprint
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants