public void Process(GetContentEditorWarningsArgs args) { Item currentItem = args.Item; if (currentItem == null) return; if (!Sitecore.Context.User.IsAuthenticated) return; var state = currentItem.State.GetWorkflowState(); if (state != null && !state.FinalState) { using (new SecurityModel.SecurityDisabler()) { Database masterDb = Factory.GetDatabase(DbName); Item stateItem = masterDb.GetItem(state.StateID); if (stateItem != null && TemplateName.Equals(stateItem.TemplateName, StringComparison.InvariantCultureIgnoreCase)) { string timeFrameString = stateItem[TimeFieldName]; if (string.IsNullOrEmpty(timeFrameString)) return; TimeSpan timeFrame = DateUtil.ParseTimeSpan(timeFrameString, TimeSpan.Zero); if (timeFrame == TimeSpan.Zero) return; if (IsInSelectedList(stateItem.Fields[RecipientsFieldName]) && WorkflowHelper.IsTimeLimitExceeded(currentItem, currentItem.State.GetWorkflow(), timeFrame)) { AddWarning(args); } } } } }
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; } } }
public void Process(GetContentEditorWarningsArgs args) { Assert.ArgumentNotNull(args, "args"); foreach (var libraryItem in ModuleManager.GetFeatureRoots(IntegrationPoint)) { if (!libraryItem.HasChildren) return; foreach (var scriptItem in libraryItem.Children.ToList()) { using (var session = ScriptSessionManager.NewSession(ApplicationNames.Default, true)) { session.SetVariable("pipelineArgs", args); try { session.SetItemLocationContext(args.Item); session.ExecuteScriptPart(scriptItem, false); } catch (Exception ex) { Log.Error(ex.Message, this); } } } } }
public new void Process(GetContentEditorWarningsArgs args) { if (Settings.IsAutomaticContentTestingEnabled && args.Item != null && !AddSuspendedTestWarning(args) && !AddActiveTestWarning(args) && !AddPartOfActiveTestWarning(args) && testCandidateInitiator.GetTestInitiator(args.Item) == TestCandidatesInitiatorsEnum.Notification) { AddContentEditorTestCandidateNotification(args); } }
/// <summary> /// Called when the content editor warnings are going to be evaluated. /// </summary> /// <param name="args"></param> public void Process(GetContentEditorWarningsArgs args) { Assert.IsNotNull(args, "args"); Item sourceItem = args.Item; Assert.IsNotNull(sourceItem, "args.Item"); ProcessGeneralWarning(args); }
public void Process(GetContentEditorWarningsArgs args) { Assert.ArgumentNotNull(args, "args"); Func <Item, bool> filter = si => si.IsPowerShellScript() && !string.IsNullOrWhiteSpace(si[Templates.Script.Fields.ScriptBody]) && RulesUtils.EvaluateRules(si[Templates.Script.Fields.EnableRule], args.Item); foreach (var libraryItem in ModuleManager.GetFeatureRoots(IntegrationPoint)) { var applicableScriptItems = libraryItem?.Children?.Where(filter).ToArray(); if (applicableScriptItems == null || !applicableScriptItems.Any()) { return; } foreach (var scriptItem in applicableScriptItems) { using (var session = ScriptSessionManager.NewSession(ApplicationNames.Default, true)) { session.SetVariable("pipelineArgs", args); try { session.SetItemLocationContext(args.Item); session.ExecuteScriptPart(scriptItem, false); } catch (Exception ex) { PowerShellLog.Error($"Error while invoking script '{scriptItem?.Paths.Path}' in Content Editor Warning pipeline.", ex); } } } } }
// Adds warning message to Content Editor and specifies its details protected virtual void AddWarning(GetContentEditorWarningsArgs args) { var warning = args.Add(); warning.Title = Globalization.Translate.Text(WarningTitleKey); warning.Text = Globalization.Translate.Text(WarningTextKey); }
public void Process(GetContentEditorWarningsArgs args) { Assert.ArgumentNotNull(args, "args"); foreach (var libraryItem in ModuleManager.GetFeatureRoots(IntegrationPoint)) { if (!libraryItem.HasChildren) { return; } foreach (var scriptItem in libraryItem.Children.ToList()) { using (var session = ScriptSessionManager.NewSession(ApplicationNames.Default, true)) { session.SetVariable("pipelineArgs", args); try { session.SetItemLocationContext(args.Item); session.ExecuteScriptPart(scriptItem, false); } catch (Exception ex) { PowerShellLog.Error($"Error while invoking script '{scriptItem?.Paths.Path}' in Content Editor Warning pipeline.", ex); } } } } }
/// <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); } }
/// <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 void GetNotifications(GetContentEditorWarningsArgs arguments, Item contextItem) { if (arguments == null) return; var wfModel = new ItemWorkflowModel(contextItem); if (wfModel.ShowNotification) { SetNotification(arguments, wfModel); } }
/// <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 new bool AddPartOfActiveTestWarning(GetContentEditorWarningsArgs args) { if (new TestingSearch().GetRunningTestsWithDataSourceItem(args.Item).Any()) { args.Add(Translate.Text("This component is part of an active test."), Translate.Text("If you edit the content it could have a negative impact on statistical significance of the test.")); return(true); } return(false); }
private bool IsSamePath(GetContentEditorWarningsArgs args, SiteContext siteContext, string requestPath) { //UrlOptions urlOptions = DisplayLinks.GetItemUrlOptions(siteContext); //urlOptions.LanguageEmbedding = LanguageEmbedding.Never; //string itemUrl = LinkManager.GetItemUrl(args.Item, urlOptions); string itemUrl = UrlFromItemCompare(args.Item, siteContext); Uri uri = new Uri(itemUrl); return(uri.LocalPath.Equals(requestPath, StringComparison.OrdinalIgnoreCase) || (uri.LocalPath + ".aspx").Equals(requestPath, StringComparison.OrdinalIgnoreCase)); }
public void Process(GetContentEditorWarningsArgs args) { Item item = args.Item; if (item == null) { return; } Check(item, args); }
public void Process(GetContentEditorWarningsArgs arguments) { Assert.ArgumentNotNull(arguments, "arguments"); if (arguments.Item != null) { foreach (var ds in arguments.Item.GetAllUniqueDataSourceItems()) { GetNotifications(arguments, ds); } } }
public void Process(GetContentEditorWarningsArgs args) { if (args == null || args.Item == null) { return; } var warning = args.Add(); warning.Title = "Item Child Count"; warning.Text = args.Item.Children.Count.ToString(); }
public void Process(GetContentEditorWarningsArgs args) { Assert.ArgumentNotNull(args, "args"); if (args.Item != null) { IExportExecuter exportExecuter = MediaFrameworkContext.GetExportExecuter(args.Item); if (exportExecuter != null && exportExecuter.IsNew(args.Item)) { args.Add(Translate.Text(Translations.NotExportedWarningTitle), Translate.Text(Translations.NotExportedWarningText)); } } }
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); }
public void GetNotifications(GetContentEditorWarningsArgs arguments, Item contextItem) { if (arguments == null) { return; } var wfModel = new ItemWorkflowModel(contextItem); if (wfModel.ShowNotification) { SetNotification(arguments, wfModel); } }
private static void Check(Item item, GetContentEditorWarningsArgs args) { var path = item.Paths.FullPath; if (path.StartsWith("/sitecore/content/")) { var itemlanguage = item.Language; var site = GetSiteInfo(item); if (site.Name == "shell") { //ignore no content site found for this item. return; } var altlanguages = GetAltLanguagesFromConfig(site); var languages = new List <Language>(); if (!altlanguages.Any()) { //no altlanguage sitconfig found try site root item. languages = GetLanguagesFromRootItem(site, item); } if (!languages.Any()) { //no language configured, use the default language //Or altlanguage in config add the default laguage to the list var defaultLanguage = site.Language; if (string.IsNullOrEmpty(defaultLanguage)) { //language attribute is optional, if not present use default language. defaultLanguage = Sitecore.Configuration.Settings.DefaultLanguage; } languages.Add(LanguageManager.GetLanguage(defaultLanguage)); } if (altlanguages.Any()) { languages.AddRange(altlanguages); } if (!languages.Contains(itemlanguage)) { AddWarning(item, args, languages, site.Name); return; } CheckTranslations(item, args, languages, site); } else { // item is not in content, not a website, so a system/ template / layout item. maybe it is nice to see the "en" version ProcessNonSiteItem(item, args); } }
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); } }
/// <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"; } }
private void SetNotification(GetContentEditorWarningsArgs arguments, ItemWorkflowModel wfModel) { var editorNotification = arguments.Add(); editorNotification.Title = "Datasource Item in Workflow"; editorNotification.Text = wfModel.GetEditorDescription(false); editorNotification.Icon = wfModel.WorkflowState.Icon; if (wfModel.HasWriteAccess()) { foreach (var command in wfModel.Commands) { editorNotification.AddOption(command.DisplayName, new WorkflowCommandBuilder(wfModel.ContextItem, wfModel.Workflow, command).ToString()); } } }
private void GetContentEditorWarnings([NotNull] XmlWriter output, [NotNull] Item item) { Assert.ArgumentNotNull(output, nameof(output)); Assert.ArgumentNotNull(item, nameof(item)); var getContentEditorWarningsArgs = new GetContentEditorWarningsArgs(item) { ShowInputBoxes = true, HasSections = true }; try { CorePipeline.Run("getContentEditorWarnings", getContentEditorWarningsArgs); } catch (Exception ex) { Log.Error("Failed to load content editor warnings", ex, this); return; } if (getContentEditorWarningsArgs.Warnings.Count <= 0) { return; } output.WriteStartElement("warnings"); foreach (var warning in getContentEditorWarningsArgs.Warnings) { if (string.IsNullOrEmpty(warning.Text)) { continue; } output.WriteStartElement("warning"); output.WriteAttributeString("title", warning.Title); output.WriteAttributeString("isexclusive", warning.IsExclusive ? "1" : "0"); output.WriteAttributeString("isfullscreen", warning.IsFullscreen ? "1" : "0"); output.WriteAttributeString("hidefields", warning.HideFields ? "1" : "0"); output.WriteAttributeString("icon", Images.GetThemedImageSource(warning.Icon, ImageDimension.id16x16)); output.WriteValue(warning.Text); output.WriteEndElement(); } output.WriteEndElement(); }
public void Process(GetContentEditorWarningsArgs args) { GetContentEditorWarningsArgs.ContentEditorWarning contentEditorWarning; if (args.Item.IsProjectItem()) { string project = args.Item.ProjectTitle(); string output = string.Format(" <a href=\"#\" onclick='javascript:return scForm.invoke(\"{0}\")' title=\"View project items\">[ View project items ]</a>", string.Format("Project:ViewItems(Id={0})", args.Item.ID)); contentEditorWarning = args.Add(); contentEditorWarning.Title = "Sitecore Project"; contentEditorWarning.Text = "This item is part of the '" + project + "' project " + output; } }
private void BuildWarning(GetContentEditorWarningsArgs args) { GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add(); warning.Icon = IconPath; warning.Title = Translate.Text(TitleKey); String format = Translate.Text(TextKey); String date = DateUtil.IsoDateToDateTime(args.Item[Constants.FieldNames.Refreshed]).ToShortDateString(); String message = String.Format(format, date); warning.Text = message; warning.AddOption(OptionKey, Constants.CommandNames.Refresh); warning.IsExclusive = false; warning.HideFields = false; }
public void Process(GetContentEditorWarningsArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.IsNotNull(args.Item, "args.Item"); Assert.ArgumentNotNullOrEmpty(TitleKey, "TitleKey"); Assert.ArgumentNotNullOrEmpty(TextKey, "TextKey"); Assert.ArgumentNotNullOrEmpty(OptionKey, "OptionKey"); Assert.ArgumentNotNullOrEmpty(IconPath, "IconPath"); if (!HasValidTemplate(args.Item) || !args.Item.Versions.IsLatestVersion() || !ItemIsStale(args.Item)) return; BuildWarning(args); }
public void Process(GetContentEditorWarningsArgs args) { Item currentItem = args.Item; if (currentItem == null) { return; } if (!Sitecore.Context.User.IsAuthenticated) { return; } var state = currentItem.State.GetWorkflowState(); if (state != null && !state.FinalState) { using (new SecurityModel.SecurityDisabler()) { Database masterDb = Factory.GetDatabase(DbName); Item stateItem = masterDb.GetItem(state.StateID); if (stateItem != null && TemplateName.Equals(stateItem.TemplateName, StringComparison.InvariantCultureIgnoreCase)) { string timeFrameString = stateItem[TimeFieldName]; if (string.IsNullOrEmpty(timeFrameString)) { return; } TimeSpan timeFrame = DateUtil.ParseTimeSpan(timeFrameString, TimeSpan.Zero); if (timeFrame == TimeSpan.Zero) { return; } if (IsInSelectedList(stateItem.Fields[RecipientsFieldName]) && WorkflowHelper.IsTimeLimitExceeded(currentItem, currentItem.State.GetWorkflow(), timeFrame)) { AddWarning(args); } } } } }
/// <summary> /// Displays a warning if Lite data is being used. /// </summary> /// <param name="args"></param> private void ProcessGeneralWarning(GetContentEditorWarningsArgs args) { if (Settings.GetBoolSetting("Sitecore.SharedSource.MobileDeviceDetector.Enabled", false)) { var session = HttpContext.Current.Session; if (session != null && session[SESSION_KEY] == null && WebProvider.ActiveProvider != null && "Lite".Equals(WebProvider.ActiveProvider.DataSet.Name)) { AddWarning(args, Messages.GeneralUpgradeTitle, Messages.GeneralUpgradeMessage); session[SESSION_KEY] = new object(); } } }
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; }
// 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 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 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); } }
/// <summary> /// Set the Validator warning messages if the Datasource Item is not in final work flow set at renderings on the Item /// </summary> /// <param name="item"></param> /// <param name="args"></param> protected void SetValidatorWarningMessages(Item item, GetContentEditorWarningsArgs args) { // get all the rendering at the item RenderingReference[] renderings = item.Visualization.GetRenderings(Sitecore.Context.Device, false); foreach (RenderingReference rendering in renderings) { if (rendering.Settings != null) { Item dataSourceItem = Utility.GetDataSourceItem(rendering.Settings.DataSource, item); if (dataSourceItem != null) { // check the state of the item if (!Utility.IsItemInFinalWorkflowState(dataSourceItem, workflowStateIsFinal)) AddWarningOptions(dataSourceItem); } } } }
/// <summary> /// Process the pipeline processor. /// </summary> /// <param name="args"></param> public void Process(GetContentEditorWarningsArgs args) { if (args.Item == null || (!args.Item.TemplateID.Equals(ItemIds.Templates.HostNameRewriteRule) && !args.Item.TemplateID.Equals(ItemIds.Templates.UrlRewriteRule))) { // Only apply the notifications to rewrite rule items. return; } if (args.Item.TemplateID.Equals(ItemIds.Templates.HostNameRewriteRule)) { // Add a Content Editor warning with instructions on how to use hostname rewrite rules. args.Add("How to use Hostname rewrite rules", this.GetHostNameRuleHelp()); } if (args.Item.TemplateID.Equals(ItemIds.Templates.UrlRewriteRule)) { // Add a Content Editor warning with instructions on how to use url rewrite rules. args.Add("How to use URL rewrite rules", this.GetUrlRuleHelp()); } }
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) { var exclusive = args.Warnings.FirstOrDefault(x => x.IsExclusive); if (exclusive != null) { foreach (var warning in args.Warnings.ToArray()) { if (warning.Title.StartsWith("JSON")) { continue; } if (!warning.IsExclusive) { args.Warnings.Remove(warning); } } exclusive.IsExclusive = false; } }
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; } } }
public void Process(GetContentEditorWarningsArgs args) { Assert.ArgumentNotNull(args, nameof(args)); var item = args.Item; Assert.IsNotNull(item, "item to process"); var databaseName = item.Database.Name; var itemID = item.ID; JsonDataProvider dataProvider; if (!JsonDataProvider.Instances.TryGetValue(databaseName, out dataProvider) || dataProvider == null) { return; } var mappings = dataProvider.Mappings.OfType<IFileMapping>().ToArray(); if (mappings.Length == 0) { return; } var mapping = mappings.FirstOrDefault(x => x.GetItemDefinition(itemID) != null); if (mapping != null) { var jsonItem = args.Add(); jsonItem.Title = "JSON Read-Only Item"; jsonItem.Text = $"This item is stored in <b>{mapping.Name}</b> file mapping{(mapping.ReadOnly ? ", but is read-only as configured in the mapping settings" : "")}. The file path is:<br />{MainUtil.MapPath(mapping.FilePath)}"; } IFileMapping overrideMapping = null; var overrideJsonMapping = Registry.GetValue("overrideJsonMapping"); if (!string.IsNullOrEmpty(overrideJsonMapping)) { mapping = mappings.FirstOrDefault(m => m.DisplayName == overrideJsonMapping && m.AcceptsNewChildrenOf(item.ID)); overrideMapping = mapping; } var firstMapping = mappings.FirstOrDefault(m => m.AcceptsNewChildrenOf(item.ID)); mapping = mapping ?? firstMapping; if (mapping == null) { return; } var createChildren = args.Add(); createChildren.Title = "JSON Children"; createChildren.Text = $"All new children of this item will be stored in the <b>{mapping.Name}</b> file mapping. The file path is:<br />{MainUtil.MapPath(mapping.FilePath)}"; if (mappings.Length > 1) { foreach (IFileMapping otherMapping in mappings) { if (otherMapping == mapping || !otherMapping.AcceptsNewChildrenOf(itemID)) { continue; } var reset = overrideMapping != null && firstMapping == otherMapping; if (reset) { createChildren.Options.Add(new Pair<string, string>("Change to " + otherMapping.DisplayName + " (remove override)", "json:override(action=reset)".FormatWith(HttpUtility.UrlEncode(otherMapping.DisplayName)))); } else { createChildren.Options.Add(new Pair<string, string>("Change to " + otherMapping.DisplayName, "json:override(id={0})".FormatWith(HttpUtility.UrlEncode(otherMapping.DisplayName)))); } } } }