Neelesh
Neelesh

Reputation: 496

Using custom sitecore data item clone notification

I understand that you can add new Notification for usage when cloning data items.

Where do you specify where you should use the custom Notification class?

Upvotes: 1

Views: 477

Answers (1)

Derek Dysart
Derek Dysart

Reputation: 1396

We display a warning on items that have been cloned. The trick is to use the "getContentEditorWarnings" pipeline:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <pipelines>
            <getContentEditorWarnings>
                <processor type="Example.OriginalItem, Example" patch:after="processor[@type='Sitecore.Pipelines.GetContentEditorWarnings.Notifications, Sitecore.Kernel']" />
            </getContentEditorWarnings>
        </pipelines>
    </sitecore>
</configuration>  

Then the code for this pipeline is:

using Sitecore.Globalization;
using Sitecore.Pipelines.GetContentEditorWarnings;

namespace Example
{
    public class OriginalItem
    {
        public void Process(GetContentEditorWarningsArgs args)
        {
            var item = args.Item;

            if ((item == null) || item.GetClones().Count() == 0) return;
            var warning = args.Add();
            warning.Title = "This Item has clones";
            warning.IsExclusive = false;
        }
    }
}

Not really germane to your question, but in this example, we use the links db to find if the item has clones:

public static IEnumerable<Item> GetClones(this Item original)
{
    Assert.ArgumentNotNull(original, "source");
    return (from link in Globals.LinkDatabase.GetReferrers(original)
            select link.GetSourceItem() into clone
            where ((clone != null) && (clone.Source != null)) && (clone.Source.ID == original.ID)
            select clone);
}

Upvotes: 1

Related Questions