Run code when Publishing Restriction is saved in Sitecore

旧城冷巷雨未停 提交于 2019-12-02 08:01:14
Lukas Kozak

The time restrictions are stored in the "__Valid to" and "__Valid from" fields. Attach a new pipe like this:

 <event name="item:saved">
        <handler type="Test.ValidTest, Test" method="OnItemSaved" />
 </event>

And then test if those fields changed and do your thing:

public class ValidTest
{
    private static readonly ID __Validfrom = new ID("{C8F93AFE-BFD4-4E8F-9C61-152559854661}");
    private static readonly ID __Validto = new ID("{4C346442-E859-4EFD-89B2-44AEDF467D21}");

    public void OnItemSaved(object sender, EventArgs args)
    {
        Item obj = Event.ExtractParameter(args, 0) as Item;
        if (obj == null)
            return;
        //if (!(obj.TemplateID == YourTemplateId)) //restrict this to a limited set of templates if possible
        //    return;
        try
        {
            ItemChanges itemChanges = Event.ExtractParameter(args, 1) as ItemChanges;
            if (itemChanges != null &&
                (itemChanges.FieldChanges.Contains(__Validfrom) || itemChanges.FieldChanges.Contains(__Validto)))
            {
                //YOUR THING here      
                Log.Info("Changed!", (object)this);
            }
        }
        catch (Exception ex)
        {
            Log.Error("failed", ex, (object)this);
        }
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!