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

"text_enabled" plugins in Text plugin become uneditable after saving #405

Closed
czpython opened this issue Dec 22, 2016 · 5 comments
Closed

Comments

@czpython
Copy link
Contributor

Taken from django-cms/django-cms#5787 by @bcdickinson:

Using a simplified version of the HelloPlugin class from the tutorial, but with text_enabled set to True:

from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from cms.models.pluginmodel import CMSPlugin

from django.utils.translation import ugettext_lazy as _
from django.templatetags.static import static

class HelloPlugin(CMSPluginBase):
    model = CMSPlugin
    render_template = "hello_plugin.html"
    cache = False
    text_enabled = True

    def icon_src(self, instance):
        return static('user.svg')

plugin_pool.register_plugin(HelloPlugin)

hello_plugin.html:

<h1>Hello</h1>

When it's first added to a text plugin everything works as expected:
first

... however, once the containg Text plugin is saved and reopened then the content of the plugin ("Hello") is no longer a plugin block, but editable text. Additionally, the <cms-plugin> element is now empty in the source view:

<p>Real text content</p>

<p><cms-plugin alt="Hello Plugin - 21 " id="21" render-plugin="true" title="Hello Plugin - 21"></cms-plugin></p>

<h1>Hello</h1>

<p>&nbsp;</p>

Saving and reopening the parent text plugin adds a new occurrence of the text every time after this, too:

<p>Real text content</p>

<p><cms-plugin alt="Hello Plugin - 21 " id="21" render-plugin="true" title="Hello Plugin - 21"></cms-plugin></p>

<h1>Hello</h1>

<p>&nbsp;</p>

<h1>Hello</h1>

<p>&nbsp;</p>
@jakob-o
Copy link
Contributor

jakob-o commented Feb 1, 2017

Hi,

just stumbled across this as well... When inserting a link (as a plugin) and saving the text plugin, the link afterwards is only editable as if it was linked from the editor via the 'Link' control and does not show the link plugin admin. Is this confirmed / does a fix exist?

Regards

Jakob

EDIT: After editing and saving the text plugin again the link plugin originally <cms-plugin> becomes <a>

@jakob-o
Copy link
Contributor

jakob-o commented Feb 1, 2017

I was able to solve my issue by adding cms-plugin to my allowedContent settings:

...
    'allowedContent': [
        'h2',
        'b',
        'i',
        'a[href]',
        # Child plugins are stored in the body with <cms-plugin> tags
        'cms-plugin[*]',
    ],
...

@vxsx
Copy link
Contributor

vxsx commented Feb 2, 2017

Thanks @jakob-o ! We'll add this to the documentation.

@bcdickinson could you please check if that would solve your problem as well?

@bcdickinson
Copy link
Contributor

I'm not sure where the setting @jakob-o changed is, but that didn't seem to be the problem for me.

Having had time to take a look at this myself again, I managed to track the issue down to broken regexes for parsing HTML in djangocms_text_ckeditor/ckeditor_plugins/cmsplugins/plugin.js (I'm using version 3.4.0, but the same bug exists in master).

The first was a problem in detecting whether the outermost element of the plugins rendered HTML was block-level. It was broken for tags with no whitespace or attributes (e.g. the <h1> from the original report).

The second was an error in the wrapping and unwrapping of the <cms-plugin> elements to <div>s and back for previewing of plugins that render as block-level elements. It was broken if the opening and closing <cms-plugin> tag weren't on the same line.

I've patched it here: https://github.com/bcdickinson/djangocms-text-ckeditor/commit/beb32a83880af4a693c51ee8d27a1443bf21b848

Is there a test suite I can run? Sorry, new to contributing patches!

@vxsx
Copy link
Contributor

vxsx commented Feb 2, 2017

sadly there're currently no automated tests for the frontend part of djangocms-text-ckeditor, only manual testing. it's on my todo list but i don't think i'll be able to do it soon

it's still great if you could send us the pull request with this patch :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants