I want to trigger an event whenever editor removes a block (using "Remove" on the Content Area) and when a user click on "Move to Trash" on a block in the asset pane.

I find DataFactory.Instance.MovedContent event which is firing on every click on "Move to Trash"

But while clicking on Remove on the Content Area its not firing.

Update:-

I am doing these steps to achieve clicking on remove

  1. Register event handlers for saving event and saved event for the page.

  2. In saving event, get the page that is being saved, get the block ids from the content area by ContentArea.Items. Use the contentlink.ID property.

  3. Store those ids in a List, store it in memory somewhere, preferably in httpcontext.items collection since you only need it for the request but a short lived cache also works. Now you know the ids of all blocks before the change by editor.

  4. In saved event, get a new list of ids like above. Now you know the ids after editor change. Some block ids will be missing. Handle those by whatever you want to do...

    void Instance_SavingContent(object sender, ContentEventArgs e)
    {
        if (e.Content is ListPdfDocumentBlock)
        {
            var properties = e.Content.GetType().GetProperties().Where(i => i.PropertyType == typeof(ContentArea));
            if (properties != null)
            {
                List<int> ids = new List<int>();
                foreach (var property in properties)
                {
                    ContentArea contentArea = property.GetValue(e.Content) as ContentArea;
                    if (contentArea != null)
                    {
                        foreach (ContentAreaItem contentAreaItem in contentArea.Items)
                        {
                            IContent itemContent = contentAreaItem.GetContent();
                            ids.Add(itemContent.ContentLink.ID);
                        }
                    }
                }
                HttpContext.Current.Items.Add("pdfId", ids);
            }
        }
    }
    

But the problem with this code is,its always returning updated ids. then how i will compare from old to new to identify which block is removed.

1

There are 1 best solutions below

7
On

When you remove something from a content area, the item reference is simply removed from that content area. The actual content (for example block/media) removed from the content area isn't actually moved/deleted (it will still exist where it was created, commonly in some asset folder).

So, the only thing happening when something is removed from a content area is that the content containing the content area is changed. The removed item is unchanged.

You could hook up the PublishingContent event and compare the content being published to the currently published version (if any) and compare the items in its content area to see if anything was added or removed.