Create your own ContentEditorWarnings in Sitecore

A ContentEditorWarning is the yellow box at the top of the Sitecore content editor. This box can be used for numerous purposes. Sitecore itself uses it if you have no access to the item, for workflow messages, protected items etc.

In a recent project we developed the concept of “local content”, i.e. pages in the website that only exists in one language (usually not the default language). The website is a corporate website with 15 or more languages. Most of the content is corporate and is therefore translated into every language. But a few pages are language-specific and will only contain one language. In order to visually mark these items, we created (among other tools) a content editor warning:

Local Content ContentEditorWarning

Local Content ContentEditorWarning

To create a ContentEditorWarning, you must implement a processor and apply it to the getContentEditorWarnings pipeline. First the code:

using Sitecore.Pipelines.GetContentEditorWarnings;

namespace PT.LocalContent.Shell.ContentEditorWarnings
  public class IsLocalContent
    public void Process(GetContentEditorWarningsArgs args)
      Item item = args.Item;
      if (item == null)
      // Here is some code that identifies my item as a local item.
      // It is not relevant for the explanation of my code so I have removed it

      GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add();
      warning.Icon = content.Flag;
      warning.Title = Translate.Text("Local content");
      warning.Text = Translate.Text("This item is local content");

      Version[] versionNumbers = item.Versions.GetVersionNumbers(false);
      if ((versionNumbers == null) || (versionNumbers.Length <= 0))
        warning.Text += "<br/><br/>" + string.Format(Translate.Text("The current item does not have a version in \"{0}\"."), item.Language.GetDisplayName());
        warning.Text += "<br/>" + Translate.Text("To create a version, click Add a New Version or click Add on the Versions tab.");
        warning.AddOption(Translate.Text("Add a new version."), "item:addversion");
        warning.IsExclusive = true;
        warning.HideFields = true;

Then you have to add the code to the getContentEditorWarnings pipeline (my code is on line 4):

  <processor type="Sitecore.Pipelines.GetContentEditorWarnings.ItemNotFound, Sitecore.Kernel" />
  <processor type="Sitecore.Pipelines.GetContentEditorWarnings.CanReadLanguage, Sitecore.Kernel" />
  <processor type="PT.LocalContent.Shell.ContentEditorWarnings.IsLocalContent, PT.LocalContent" />

There is one catch left. Notice that the GetContentEditorWarningsArgs.ContentEditorWarning has a property called IsExclusive? Setting IsExclusive breaks the pipeline, and displays the processor without any other content editor warnings.

The first processor that has the IsExclusive = true is Sitecore’s own HasNoVersions processor:

<processor type="Sitecore.Pipelines.GetContentEditorWarnings.HasNoVersions, Sitecore.Kernel" />

Applying processors after this processor will not show if the item has no versions. So if your processor works for any item regardless of versions, it should be applied before the HasNoVersions.

About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in .net, c#, Sitecore 6 and tagged , , , . Bookmark the permalink.

5 Responses to Create your own ContentEditorWarnings in Sitecore

  1. Lello says:

    Thank your for the great info… But based on your notes below, If I want selects the parent of a current context what should I use:
    .. dot do or parent ::item

    >>>•Only 4 axes are supported (parent:: child:: ancestor:. and descendant::)
    •Some special attributes cannot be searched (id, name, key, template, ..)


  2. briancaos says:

    The snippet you have taken comes from another article about the Sitecore fast query ( The fast Query is a special tool for special situations.

    To select the parent of a current item, simply do the following:

    Item parentItem = Sitecore.Context.Item.Parent;

    For more advanced stuff, like getting all parents, use the Axes namespace on the Item:

    Item[] ancestors = Sitecore.Context.Item.Axes.GetAncestors();

    Use Fast Query for searching in the entire system.

  3. Pingback: Creating fallback values using the RenderField pipeline « Brian Pedersen’s Sitecore and .NET Blog

  4. Pingback: Employ the Template Method Design Pattern for Content Editor Warnings in Sitecore «

  5. Pingback: Utilize the Strategy Design Pattern for Content Editor Warnings in Sitecore «

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s