运行 Sitecore 中保存发布限制时的代码

Run code when Publishing Restriction is saved in Sitecore

当作者保存项目的发布限制时,我需要 运行 编码。

我该怎么做?

时间限制存储在“__Valid 到”和“__Valid 从”字段中。像这样连接一个新管道:

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

然后测试这些字段是否更改并执行您的操作:

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);
        }
    }
}