How to know a content item's field is changed

Topics: Administration, Customizing Orchard
Jan 3, 2012 at 2:54 AM

I am working on Rules, and I'm a bit confuse of the Events . I need to create a Rule that do an action whenever a content item's field change, for example the field Status change from true to false . Is OnVersioned event can do that ? Or if I need to create new event , how do I do that ?

I have read Sebastien's post here : . But i need more details.

Jan 3, 2012 at 4:00 AM

Overriding Publishing in a handler should give you the new and old versions of the item.

Jan 3, 2012 at 6:16 AM
bertrandleroy wrote:

Overriding Publishing in a handler should give you the new and old versions of the item.

Can u give a sample code, I'm still confuse about it.

Jan 3, 2012 at 6:21 AM

No, I don't have any. Write a handler, override Publishing, use intellisense on the context object.

Jan 3, 2012 at 6:36 AM

I have written a new Handler like this, just copy the Content.Rules code , but i didnt know how to register and trigger that event ...


public interface ITestContentHandler : IDependency {
        void Changed(ChangeStatusContentContext context);

    public abstract class TestContentHandler : ITestContentHandler 
        protected TestContentHandler ()
            Filters = new List<IContentFilter>();
            Logger = NullLogger.Instance;

        public List<IContentFilter> Filters { get; set; }
        public ILogger Logger { get; set; }

        protected void OnChanged<TPart>(Action<ChangeStatusContentContext, TPart> handler) where TPart : class, IContent
            Filters.Add(new TestInlineStorageFilter<TPart> { OnChanged = handler });

        class TestInlineStorageFilter<TPart> : TestStorageFilterBase<TPart> where TPart : class, IContent
            public Action<ChangeStatusContentContext, TPart> OnChanged { get; set; }

            protected override void Changed(ChangeStatusContentContext context, TPart instance)
                if (OnChanged != null) OnChanged(context, instance);

        void ITestContentHandler .Changed(ChangeStatusContentContext context)
            foreach (var filter in Filters.OfType<ITestContentStorageFilter>())

        protected virtual void Changed(ChangeStatusContentContext context) { }
Jan 6, 2012 at 5:57 AM

I'm not sure I get what this is supposed to do. You've got nested classes in there for no clear reason, and you didn't actually override anything. In particular you didn't override the publishing method as I had advised.

Feb 15, 2012 at 7:50 AM
Edited Feb 15, 2012 at 7:51 AM

Hello you guys,

I am trying to do the same thing as taki27, I have created the handler to override the publishing method, I have added a debug point to my content handler class but the onpublishing event never got triggered when I change the content of the item. Am I taking it wrong?


  public  class StatusHandler:ContentHandler {


     //here is my processing line


I have also tried to override onversioned but it is not getting triggered as well.
Have you guys have any advises for me please.
Feb 15, 2012 at 12:08 PM

Is your item versionable, i.e. does it have Save and Publish buttons? Otherwise only the Created event will be fired.

Feb 15, 2012 at 12:19 PM

Is "Versionable" in the sense of having a publish button different from declaring a content part as Versioned in Migrations.cs? 

Feb 15, 2012 at 12:40 PM

They're different. A content part can be defined as supporting versioning by declaring .ContentPartVersionRecord(). However this doesn't mean the content type is versioning enabled, which is done via .Draftable() on a content type definition.

Feb 15, 2012 at 2:24 PM
Edited Feb 15, 2012 at 2:25 PM

If a content part supports versioning, is it just a history of every single state the part has had, or is it a set of named states (e.g. "Published", "Draft")?

Feb 16, 2012 at 12:49 AM

Thanks randompete,


Could I ask if there is anyway that I can do a custom event, that get triggered every time a content is updated ( not by pressing the publish button but to use my own form). I have feeling that I will have to wait for the next few releases for this.



Mar 6, 2012 at 4:00 AM

Hello everyone,

I'm still stuck at this issue and hope that I could solve this in Orchard 1.4.

I realized that there is updating and updated events in the content handler class since Orchard 1.4 , and I tried to override the OnUpdating method in my custom handler. However, the problem is that it only gets run if I update the content using the default editor, if I update it manually by code, my custom OnUpdating method will not be running.

Is there a way to accomplish this, or it is just impossible?

Could you guys help me on this please, I really appreciate it.


Mar 6, 2012 at 5:02 AM

I don't get it: if it's your own code doing the updating, you know that you are updating, don't you?

Mar 6, 2012 at 6:26 AM

So to recap the idea, here is how I want it to be:

I have a content part named Status that can be attached to any content Item.

When that content item is changed and has a status updated , I want to be able to track down that event so I can find the matched rule for it.

Hope it is clearer now.


Thanks very  much

Mar 6, 2012 at 6:18 PM

Then if it is a part the edition should be done inside a Driver. And you should use BuildEditor/UpdateEditor from your controller, so that the Updating event is triggered.