Justin Greywolf
Justin Greywolf

Reputation: 847

Orchard CMS: How to cancel a remove event

I have created some code to disallow deletion of a Content Item if that item has any localized Dependencies. To do this I created a new "extension" interface and (default)class within Orchard.Framework.ContentManagement, and then created a new class within the Orchard.Localization modul, using the SuppressDependency attribute. It returns a simple Boolean value based on a query to see if there are any ContentItems that list the current item as their MasterContentItem

This is called from the AdminController within Orchard.Core.Contents, and if it returns true then I add a message and redirect to the returnUrl, otherwise the removal continues as normal.

All of this is working perfectly.

HOWEVER, I would like to refactor this to take advantage of the existing infrastructure with IContentManager and add a Removing() method to the LocalizationPartHandler.

My question is - is it possible to "cancel" the remove action based on output of ContentHandler invoked earlier...

Upvotes: 0

Views: 174

Answers (1)

Ropstah
Ropstah

Reputation: 17794

As mentioned in my comment I'm not completely sure as to what you want to accomplish, but my guess is that you want to create your own module and within that module create a Handler implementation in which you do your thing...

From what I understand is that you want to hook into the Remove event lifecycle. Handlers provide the OnRemoving which executes before the item is removed. I'm not an expert on handlers and their extension points and how you could cancel the event, but my guess is that you want to implement the following:

public class YourCustomHandler : ContentHandler {

    public YourCustomHandler(IYourCancelService yourCancelService) {
        OnRemoving<LocalizationPart>((context, part) => 
            yourCancelService.CancelRemoveEvent(context));
    }
}

Read this for more info on handlers: http://docs.orchardproject.net/Documentation/Understanding-content-handlers

Upvotes: 1

Related Questions