Created
November 2, 2012 13:16
-
-
Save janhebnes/4001318 to your computer and use it in GitHub Desktop.
Sitecore CMS - GetContentEditorWarnings AvailableLanguageVersions Quick switch between versions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Sitecore.Data.Items; | |
using Sitecore.Data.Managers; | |
using Sitecore.Globalization; | |
using Sitecore.Pipelines.GetContentEditorWarnings; | |
namespace SitecoreExtensions.Pipelines.GetContentEditorWarnings | |
{ | |
/// Added to the getContentEditorWarnings processor before FeedIsEmpty | |
public class AvailableLanguageVersions | |
{ | |
public void Process(GetContentEditorWarningsArgs args) | |
{ | |
if (args.Item == null) | |
{ | |
return; | |
} | |
GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add(); | |
Sitecore.Diagnostics.Log.Debug(warning.Icon); | |
warning.Icon = args.Item.Language.GetIcon(args.Item.Database); | |
string text = Translate.Text("Available in the following languages: "); | |
foreach (var itemVersion in args.Item.Versions.GetVersions(true).OrderBy(d=>d.Language.Name)) | |
{ | |
if (itemVersion == null) continue; | |
var meta = string.Empty; | |
if (itemVersion.Version.Number > 1) | |
{ | |
meta += " <span title=\"Version\">v" + itemVersion.Version + "</span>"; | |
} | |
if (!itemVersion.Publishing.IsPublishable(DateTime.Now, false) || !itemVersion.Publishing.IsValid(DateTime.Now, false)) | |
{ | |
meta += " <span title=\"Restricted publishing (is not available live)\">R!</span>"; | |
} | |
if (itemVersion.Publishing.PublishDate != DateTime.MinValue) | |
{ | |
meta += " <span title=\"Restricted item (publish date)\">r+" + itemVersion.Publishing.PublishDate.ToShortDateString() + "</span>"; | |
} | |
if (itemVersion.Publishing.UnpublishDate != DateTime.MaxValue) | |
{ | |
meta += " <span title=\"Restricted item (unpublish date)\">r-" + itemVersion.Publishing.UnpublishDate.ToShortDateString() + "</span>"; | |
} | |
if (itemVersion.Publishing.ValidFrom != DateTime.MinValue) | |
{ | |
meta += " <span title=\"Restricted version (valid from)\">rv+" + itemVersion.Publishing.ValidFrom.ToShortDateString() + "</span>"; | |
} | |
if (itemVersion.Publishing.ValidTo != DateTime.MaxValue) | |
{ | |
meta += " <span title=\"Restricted version (valid to)\">rv-" + itemVersion.Publishing.ValidTo.ToShortDateString() + "</span>"; | |
} | |
var display = itemVersion.Language.Name; | |
if (meta != String.Empty) | |
{ | |
display += " (" + meta.Trim() + ")"; | |
} | |
if (args.Item.Language == itemVersion.Language && args.Item.Version.Number == itemVersion.Version.Number) | |
{ | |
text += string.Format("<u><strong>[ {0} ]</strong></u>", display); | |
} | |
else | |
{ | |
text += string.Format("<a href=\"#\" onclick=\"javascript:return scForm.postEvent(this,event,'item:load(id={1},language={2},version={3})')\" title=\"Edit {4} \">[ {0} ]</a>", display, args.Item.ID, itemVersion.Language.Name, itemVersion.Version.Number, itemVersion.Language.GetDisplayName()); | |
} | |
} | |
warning.Text = text; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment