Frage

Is there a pipeline I can add to and/or event to intercept that would allow me to set the lock on an item only if a lock in the foreign system is possible? [Mainly interested with this functionality in the Media Library]

We are currently looking to provide syncing functionality with Sitecore items and I'm running through a checklist of use cases to determine feasibility. Locking an item currently needs to lock an item in the foreign system.

I read John West's blog post explaining the interception of Item Updates.

If you need to be able to block the save operation, consider the saveUI pipeline, the item:saving event, or field validators. If you need to prevent the visual effect in the user interface that indicates that Sitecore has saved the selected item, consider the saveUI pipeline or field validators.

This is useful to me later when I need to possibly block the saving of an item because of an error in the foreign system, but it does not state anything as the locking/editing begins.

I also noted on John's Important Pipelines blog post that there is no "uiEditItem" or anything that seems to note a pipeline with item editing.

War es hilfreich?

Lösung

You could propably place your own processor before "Sitecore.Pipelines.Save.CheckItemLock" in the saveUI section.

In your processor you can abort the saving of an item by calling the AbortPipeline method. If you want to check if the saved item gets locked, you can check if the lock field has changed.

Here is some example code:

public class CheckForeignLock {
    protected bool UserIsTryingToLockItem(SaveArgs args) {
        var lockfield = args.Fields.SingleOrDefault(x => x.ID == FieldIDs.Lock);
        return lockfield != null && lockfield.OriginalValue != lockfield.Value;                 
    }
    protected bool CanLock() {
        // your code
    }
    public void Process(SaveArgs args) {
        if(UserIsTryingToLockItem(args) && !CanLock()) {
            args.AbortPipeline();
        }
    }
}

And here the place where you could register your processor:

<processor mode="on" type="Sitecore.Pipelines.Save.ParseXml, Sitecore.Kernel" />
<processor mode="on" type="YourAssembly.CheckForeignLock, YourAssembly" />
<processor mode="on" type="Sitecore.Pipelines.Save.CheckItemLock, Sitecore.Kernel" />
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top