silverstripe-shortcodable icon indicating copy to clipboard operation
silverstripe-shortcodable copied to clipboard

Edit HTML Source not Saving HTML

Open prazvan opened this issue 9 years ago • 7 comments

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

prazvan avatar Nov 07 '16 13:11 prazvan

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

sheadawson avatar Nov 07 '16 22:11 sheadawson

@sheadawson will do that asap :)

prazvan avatar Nov 09 '16 09:11 prazvan

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"]

tomstgeorge avatar Nov 18 '16 04:11 tomstgeorge

Same for me.

tardinha avatar Nov 21 '16 01:11 tardinha

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

jules0x avatar Mar 01 '17 03:03 jules0x

@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.

MrJamesEllis avatar Mar 09 '17 04:03 MrJamesEllis

@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.

jules0x avatar Mar 09 '17 20:03 jules0x