Gutter Warnings: Validate That The Item Has A Version (In Current Language)

Had a need to indicate to editors that the item does not have a version in the current language and wrote up a quick Gutter validator.

public class NoLanguageVersionValidator : GutterRenderer
{
    protected override GutterIconDescriptor GetIconDescriptor(Sitecore.Data.Items.Item item)
    {
        Assert.ArgumentNotNull(item, "item");
        return !ItemHasLanguageVersion(item) ? GetGutterDescriptor() : null;
    }

    private bool ItemHasLanguageVersion(Item item)
    {
        return item.Versions.Count > 0;
    }

    private GutterIconDescriptor GetGutterDescriptor()
    {
        var icon = Sitecore.Context.Language.GetIcon(Sitecore.Context.Database);
        var descriptor = new GutterIconDescriptor();
        // Using an overlay icon and the current language's flag
        descriptor.Icon = icon + "?overlay=Applications/16x16/delete2.png";
        descriptor.Tooltip = "This item does not have a version in the current language.";
        return descriptor;

    }
}

This will display a gutter icon with the current language’s flag and a big, fat, red ‘X’ over it if the item does not have a version in the current language.

Check this post for information on how to config the gutter warning.

Posted in Sitecore
One comment on “Gutter Warnings: Validate That The Item Has A Version (In Current Language)
  1. Larre says:

    Great post.
    Shouldn’t it also be possible to add a click event on the flag to actually let the editor create the version directly from the gutter?
    Something like: descriptor.Click = String.Format(“item:createVersion(id={0})”, item.ID);

Leave a Reply to Larre Cancel reply

Your email address will not be published. Required fields are marked *

*