sheadawson / silverstripe-shortcodable

Provides a GUI for CMS users to insert Shortcodes into the HTMLEditorField + an API for developers to define Shortcodable DataObjects and Views.
MIT License
48 stars 36 forks source link

Edit HTML Source not Saving HTML #45

Open prazvan opened 8 years ago

prazvan commented 8 years ago

Hey,

So i found a weird bug when using the module with HTML Edit source.

Lets say that after you add a shortcode from the module our you want to add it manually when editing the html source, when you try to save the page as draft or published the content won't be save.

After a bit of debugging found a solution

in the shortcodable.js file

under the onbeforesubmitform callback i found out the the Editor save method wasn't called at all.

            /**
             * Make sure the editor has flushed all it's buffers before the form is submitted.
             */
            'from .cms-edit-form': {
                onbeforesubmitform: function(e) {
                    var shortcodable = tinyMCE.activeEditor.plugins.shortcodable;
                    var ed = this.getEditor();
                    var newContent = shortcodable.replacePlaceholdersWithShortcodes($(this).val(), ed);
                    $(this).val(newContent);

                    // save html - FIX
                    ed.save();

                }
            },

Thanks, Razvan

sheadawson commented 7 years ago

Great! Thanks Razvan. I had noticed that bug on a recent project but not investigated it.

Would you like to make a pull request to commit that change? If you are not experienced with this, this might be a good opportunity to have a go

prazvan commented 7 years ago

@sheadawson will do that asap :)

tomstgeorge commented 7 years ago

I just made this edit to shortcodable.js and it does fix the 'edit HTML source not saving' issue but breaks the saving of the inserted shortcode dataobject.

Now when I publish the page the embeded shortocde dataobject shows on the frontend as an image i.e. they are no longer being converted into shortcodes on save.

When I look in the database they are stored as the image and not being saved as e.g [myObject id="2"]

tardinha commented 7 years ago

Same for me.

jules0x commented 7 years ago

The fix @MrJamesEllis pushed does not fix #52 or #49 for me. A shortcode does not even need to be present on the page for the HTML Source editor to ignore the changes made. I rolled back to version ^2.0 and noted that I was able to edit the content via the HTML Source editor if I finish my edits, then open and close the HTML source editor again before attempting to save. This doesn't appear to work for ^3.0

MrJamesEllis commented 7 years ago

@jules0x I only applied the change to the 2.0 branch as that satisfies my SS version requirement. Does the change fix the issues referenced for you in 2.0 ?

The only side-effect I've had reported is that navigating away from an admin form including the HTMLEditorField with a shortcode, causes the "Changes that you made, may not be saved" alert.. when no changes were made to the field.

jules0x commented 7 years ago

@MrJamesEllis I just tried adding the changes in f9466d8 to the 2.0.9 branch and no, I get the same behaviour. Edits to the htmlsource editor are lost on save, and when switching between pages, content is transferred between the two. My solution is likely to be removing the default html source editor button and implementing a separate html editor at a later date.