Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • devRics 4 posts 71 karma points
    Dec 11, 2015 @ 23:28
    devRics
    0

    On Saving Override removes Macros from content

    I have a method overriding the Umbraco.Core.Services.ContentService.Saving. It's just adding some class to images.

    But now I started enabling some Macros to be added in the rich-text editor and the Macros disappear after saving.

    After much digging I found out that if I override the saving method some how the Macros get removes.

    If anyone else had to deal with this I would love some insight on what is going on.

    Here is how I override it:

    Umbraco.Core.Services.ContentService.Saving += OverrideSave.ContentService_Saving;
    

    And here is the my method (minus the middle boring part).

     public class OverrideSave
        {
            public static void ContentService_Saving(Umbraco.Core.Services.IContentService sender, Umbraco.Core.Events.SaveEventArgs<Umbraco.Core.Models.IContent> e)
            {
                foreach (var c in e.SavedEntities)
                {
                    var list = c.PropertyTypes.Where(x => x.PropertyEditorAlias == "Umbraco.TinyMCEv3").ToList();
    
                if (list.Count > 0)
                {
                    List<Property> propList = new List<Property>();
    
                    foreach (var i in list)
                    {
                        propList.Add(c.Properties.Where(x => x.Alias == i.Alias).FirstOrDefault());
                    }
    
                    if (propList.Count > 0)
                    {
                        foreach (var t in propList)
                        {
                            // Do a lot of fun stuff here...
    
                            t.Value = (object)doc.DocumentElement.OuterHtml;
                        }
                    }
                }
            }
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft