/// <summary> /// Called by getContentEditorWarnings pipeline to determine if a warning should be /// displayed or not if the item is configured for publish exclusion. /// Override this method for any custom implementation logic. /// </summary> /// <param name="args">content editor warning arguments</param> public virtual void Process(GetContentEditorWarningsArgs args) { Assert.ArgumentNotNull(args, "args"); try { if (!PublishExclusionsContext.Current.ShowContentEditorWarnings || args.Item == null || (Context.ContentDatabase != null && Context.ContentDatabase.Name != "master")) { return; } List <PublishExclusion> exclusions = PublishExclusionsContext.Current.GetAllPublishExclusions(args.Item); if (exclusions == null || exclusions.Count == 0) { return; } GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add(); warning.Title = WarningTitle; warning.Text = string.Join("<br/>", exclusions.Select(e => string.Format(WarningTextFormat, e.PublishingTarget, GetFormattedPublishModes(e.PublishModes)))); } catch (Exception ex) { Log.Error("Sitecore.PublishExclusions : IsExcludedFromPublish processor - error in evaluating content editor warnings", ex, this); } }
public virtual void Process(GetContentEditorWarningsArgs args) { Item item = args.Item; if (item == null) { return; } var existingSitecoreItem = new ItemData(item); PredicateResult matchingPredicate = null; foreach (var configuration in _configurations) { matchingPredicate = configuration.Resolve <IPredicate>().Includes(existingSitecoreItem); if (matchingPredicate.IsIncluded) { var evaluator = configuration.Resolve <IEvaluator>(); var warningObject = evaluator.EvaluateEditorWarning(item, matchingPredicate); if (warningObject != null) { GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add(); warning.Title = warningObject.Title; warning.Text = warningObject.Message; } } } }
public virtual void Process(GetContentEditorWarningsArgs args) { Item item = args.Item; if (item == null) { return; } var existingSitecoreItem = new ItemData(item); var configuration = _configurations.FirstOrDefault(config => config.Resolve <IPredicate>().Includes(existingSitecoreItem).IsIncluded); if (configuration != null) { var evaluator = configuration.Resolve <IEvaluator>(); var warningObject = evaluator.EvaluateEditorWarning(item); if (warningObject != null) { GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add(); warning.Title = warningObject.Title; warning.Text = warningObject.Message; } } }
/// <summary> /// Adds a warning message to the pipeline. /// </summary> /// <param name="title">Message title</param> /// <param name="message">Message text</param> /// <param name="args">Arguments for processing</param> protected void AddWarning( GetContentEditorWarningsArgs args, string title, string message) { GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add(); warning.Title = title; warning.Text = message; }
public void Process(GetContentEditorWarningsArgs args) { Item item = args.Item; // check if the current item is in final workflow state and then check for validation errors if (! Utility.IsItemInFinalWorkflowState(item, workflowStateIsFinal)) return; // set the warning Title _contentEditorWarning = args.Add(); _contentEditorWarning.Title = Sitecore.Globalization.Translate.Text("If you publish now, the current item may not render properly because the following dependencies have not been moved to a final workflow state. Click the links below to review these items:"); SetValidatorWarningMessages(item, args); }
/// <summary> /// Processes the specified args. /// </summary> /// <param name="args">The args.</param> public void Process([NotNull] GetContentEditorWarningsArgs args) { DateTime expiration = DateUtil.IsoDateToDateTime(Nexus.LicenseApi.Expiration); double minimumNumberOfDaysToWarn = 7; double.TryParse(SettingsFixed.SettingsFromMaster.DefaultNumberOfDaysToWarn.ToString(), out minimumNumberOfDaysToWarn); if (MainUtil.GetBool(SettingsFixed.SettingsFromMaster.AlwaysWarn, false) || DateTime.Now.Date > expiration.AddDays(-minimumNumberOfDaysToWarn)) { GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add(); warning.Title = SettingsFixed.SettingsFromMaster.WarningTitle; warning.Text = SettingsFixed.SettingsFromMaster.WarningSubtitle.Replace("[date]", expiration.ToLongDateString()).Replace("[url]", WebUtil.GetServerUrl()); warning.Icon = "Applications/16x16/delete.png"; } }
// Methods #region Public methods /// <summary> /// Gets the field value. /// </summary> /// <param name="args">The arguments.</param> public void Process(GetContentEditorWarningsArgs args) { if (args != null) { Item item = args.Item; if (item != null) { if (Settings.GetBoolSetting("VersionManager.ShowContentEditorWarnings", true) && VersionManager.IsItemUnderRoots(item)) { int count = item.Versions.Count; int maximum = Settings.GetIntSetting("VersionManager.NumberOfVersionsToKeep", 5); if (maximum < 1) { return; } if (count >= maximum) { GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add(); if (count == maximum) { warning.Title = Translate.Text("The current item has reached maximum allowed number of versions."); } if (count > maximum) { warning.Title = Translate.Text("The current item has exceeded maximum allowed number of versions."); warning.AddOption("Delete obsolete versions", "version:clean"); } if (Settings.GetBoolSetting("VersionManager.AutomaticCleanupEnabled", false)) { warning.Text = this.GetText(item, count - maximum + 1) + "."; } else { warning.Text = string.Empty; } warning.IsExclusive = false; warning.HideFields = false; } } } } }
public static void AddWarning(Item item, GetContentEditorWarningsArgs args, IList <Language> languages, string sitename) { GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add(); warning.Title = "You are not in the language of the current site: " + sitename; warning.Text = "Switch to the correct language"; foreach (var language in languages) { if (language != null) { warning.AddOption(string.Format("Switch to {0}", language.GetDisplayName()), string.Format(CultureInfo.InvariantCulture, "item:load(id={0},language={1})", item.ID, language.Name)); } } warning.IsExclusive = true; }
public void Process(GetContentEditorWarningsArgs args) { Assert.ArgumentNotNull(args, "args"); if (!args.Item.IsPowerShellScript() && !args.Item.IsPowerShellLibrary() && !args.Item.InheritsFrom(Templates.ScriptModule.Id)) { return; } var action = SessionElevationManager.GetToken(ApplicationNames.ItemSave).Action; var warning = new GetContentEditorWarningsArgs.ContentEditorWarning(); switch (action) { case SessionElevationManager.TokenDefinition.ElevationAction.Password: case SessionElevationManager.TokenDefinition.ElevationAction.Confirm: if (SessionElevationManager.IsSessionTokenElevated(ApplicationNames.ItemSave)) { warning.Title = "You have temporarily enabled script viewing and editing."; warning.Text = "Drop access if you no longer require it. For more information, refer to our <a href=\"https://sitecorepowershell.com/session-state-elevation/\" class=\"scEditorWarningOption\" target=\"_blank\">Documentation.</a>"; warning.AddOption("Drop access", "item:dropelevatescriptedit"); args.Warnings.Add(warning); } else { warning.HideFields = true; warning.Title = "Elevated session state is required to view and edit scripts."; warning.Text = "A security dialog will prompt you for your credentials before allowing access to view and edit scripts. For more information, refer to our <a href=\"https://sitecorepowershell.com/session-state-elevation/\" class=\"scEditorWarningOption\" target=\"_blank\">Documentation.</a>"; warning.AddOption("Elevate session", "item:elevatescriptedit"); args.Warnings.Add(warning); } break; case SessionElevationManager.TokenDefinition.ElevationAction.Block: warning.HideFields = true; warning.Title = "Elevated session state is blocked. Access to view and edit scripts is disabled."; warning.Text = "For more information, refer to our <a href=\"https://sitecorepowershell.com/session-state-elevation/\" class=\"scEditorWarningOption\" target=\"_blank\">Documentation.</a>"; args.Warnings.Add(warning); break; } }
public void Process(GetContentEditorWarningsArgs args) { Item item = args.Item; Assert.IsNotNull(item, "item"); ScheduledPublishRepo scheduledPublishRepo = new ScheduledPublishRepo(); IEnumerable <PublishSchedule> schedulesForCurrentItem = scheduledPublishRepo.GetSchedules(item.ID); if (schedulesForCurrentItem.Any()) { GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add(); warning.Icon = "Applications/32x32/information2.png"; warning.Text = "This item has been scheduled for publish."; warning.IsExclusive = false; } }
public virtual void Process(GetContentEditorWarningsArgs args) { Item item = args.Item; if (item == null) { return; } var existingSitecoreItem = new ItemData(item); if (_configurations.Any(configuration => configuration.Resolve <IPredicate>().Includes(existingSitecoreItem).IsIncluded)) { GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add(); warning.Title = RenderTitle(item); warning.Text = RenderWarning(item); } }
private static void AddTranslateWarning(Item item, GetContentEditorWarningsArgs args, IList <Sitecore.Globalization.Language> notranslation, IList <Item> fallback, string sitename) { GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add(); warning.Title = "This item is not translated for the site: " + sitename; warning.Text = "Switch to the not translated language and create a version"; foreach (var language in notranslation) { warning.AddOption(string.Format("Switch to {0}", language.GetDisplayName()), string.Format(CultureInfo.InvariantCulture, "item:load(id={0},language={1})", item.ID, language.Name)); } if (fallback.Any()) { foreach (var languageitem in fallback) { warning.AddOption(string.Format("Switch to {0} (now uses {1} language fallback)", languageitem.Language.GetDisplayName(), languageitem.OriginalLanguage.GetDisplayName()), string.Format(CultureInfo.InvariantCulture, "item:load(id={0},language={1})", item.ID, languageitem.Language.Name)); } } warning.IsExclusive = false; }
public void Process(GetContentEditorWarningsArgs args) { Item item = args.Item; Assert.IsNotNull(item, "item"); ScheduledPublishRepo scheduledPublishRepo = new ScheduledPublishRepo(); using (new LanguageSwitcher(LanguageManager.DefaultLanguage)) { IEnumerable <PublishSchedule> schedulesForCurrentItem = scheduledPublishRepo.GetSchedules(item.ID); if (schedulesForCurrentItem.Any()) { GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add(); warning.Icon = Constants.SCHEDULED_PUBLISH_ICON; warning.Text = Constants.SCHEDULED_PUBLISH_NOTIFICATION; warning.IsExclusive = false; } } }
public void Process(GetContentEditorWarningsArgs args) { Item item = args.Item; // If Item is null return if (item == null) { return; } //Check if the current item has sticky notes if (item.Fields["StickyNotes"] != null && item.Fields["StickyNotes"].Value != null) { GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add(); warning.Title = Translate.Text("Following are the sticky notes added to this item"); StringBuilder warningText = new StringBuilder(); string stickyNoteOnItem = item.Fields["StickyNotes"].Value.ToString(); if (!string.IsNullOrEmpty(stickyNoteOnItem)) { //Read through all the sticky notes available on the item var stickyNotes = JsonConvert.DeserializeObject <StickyNotes>(stickyNoteOnItem); if (stickyNotes != null && stickyNotes.notesOnAnItem != null && stickyNotes.notesOnAnItem.Any()) { foreach (var note in stickyNotes.notesOnAnItem) { if (note.Properties != null && !string.IsNullOrEmpty(note.Properties.Text)) { warningText.AppendFormat("{0} was added by {1} on {2}", note.Properties.Text, note.Properties.UserName, note.Properties.DateCreated); warningText.Append("<br>"); } } } } //Assign the sticky notes to the warning warning.Text = warningText.ToString(); } }
public void Process(GetContentEditorWarningsArgs args) { var item = args.Item; if (item == null) { return; } if (!item.IsProfileMap() || item.HasTrackingField()) { return; } GetContentEditorWarningsArgs.ContentEditorWarning key = args.Add(); key.Key = "Sitecore.Pipelines.GetContentEditorWarnings.ProfileMapTrackingFieldNotSet"; key.IsExclusive = false; key.Title = "No tracking field set on profile map."; key.Text = $"Before publishing a profile map you should associate it with a profile card or set custom profile key values."; key.HideFields = false; }
private static void ProcessNonSiteItem(Item item, GetContentEditorWarningsArgs args) { Version[] versionNumbers = item.Versions.GetVersionNumbers(false); if (versionNumbers != null && versionNumbers.Length > 0) { return; } LanguageCollection languages = LanguageManager.GetLanguages(Sitecore.Context.ContentDatabase); int lancount = 0; var languageList = new List <string>(); foreach (Language language in languages) { if (HasLanguage(item, language)) { lancount++; languageList.Add(language.ToString()); if (lancount > 3) { //limit to 4, but add en if precent because this is the default if (!languageList.Contains("en")) { var defaultlang = Sitecore.Globalization.Language.Parse("en"); if (defaultlang != null && HasLanguage(item, defaultlang)) { languageList.Add(defaultlang.ToString()); } } break; } } } if (languageList.Any()) { GetContentEditorWarningsArgs.ContentEditorWarning contentEditorWarning = args.Add(); contentEditorWarning.Title = string.Format(Translate.Text("The current item does not have a version in \"{0}\"."), (object)item.Language.GetDisplayName()); if (item.Access.CanWriteLanguage() && item.Access.CanWrite()) { contentEditorWarning.Text = Translate.Text("To create a version, click Add a New Version or Switch language."); contentEditorWarning.AddOption(Translate.Text("Add a new version."), "item:addversion"); foreach (var languageitem in languageList) { contentEditorWarning.AddOption(string.Format("Switch to {0}", languageitem), string.Format(CultureInfo.InvariantCulture, "item:load(id={0},language={1})", item.ID, languageitem)); } contentEditorWarning.IsExclusive = true; } else { contentEditorWarning.IsExclusive = false; } contentEditorWarning.HideFields = true; contentEditorWarning.Key = HasNoVersions.Key; } else { GetContentEditorWarningsArgs.ContentEditorWarning contentEditorWarning = args.Add(); contentEditorWarning.Title = string.Format(Translate.Text("The current item does not have a version in \"{0}\"."), (object)item.Language.GetDisplayName()); if (item.Access.CanWriteLanguage() && item.Access.CanWrite()) { contentEditorWarning.Text = Translate.Text("To create a version, click Add a New Version or click Add on the Versions tab."); contentEditorWarning.AddOption(Translate.Text("Add a new version."), "item:addversion"); contentEditorWarning.IsExclusive = true; } else { contentEditorWarning.IsExclusive = false; } contentEditorWarning.HideFields = true; contentEditorWarning.Key = HasNoVersions.Key; } }