public virtual void Process(GetLookupSourceItemsArgs args) { var replaceTokensArgs = new ReplaceLookupSourceQueryTokensArgs(args.Item, args.Source); CorePipeline.Run("elision.replaceLookupSourceQueryTokens", replaceTokensArgs); args.Source = replaceTokensArgs.Query; }
public void ReturnsFalseForNullQuery() { using (var db = new Db() { new DbItem("page1"), new DbItem("page2") }) { var page1 = db.GetItem("/sitecore/content/page1"); var args = new GetLookupSourceItemsArgs() { Item = page1 }; var context = new GetLookupsourceItemsRuleContext(args); var condition = new QueryContainsTokenCondition <GetLookupsourceItemsRuleContext>() { Token = "ItemField" }; var ruleStack = new RuleStack(); condition.Evaluate(context, ruleStack); ruleStack.Should().HaveCount(1); ruleStack.Pop().Should().Be(false); } }
public void AbortsRuleProcessing() { using (var db = new Db() { new DbItem("page1"), new DbItem("page2") }) { var page1 = db.GetItem("/sitecore/content/page1"); var page2 = db.GetItem("/sitecore/content/page2"); var args = new GetLookupSourceItemsArgs() { Item = page1, Source = "./*" }; var ctx = new GetLookupsourceItemsRuleContext(args); var action = new ForceQueryResultAction <GetLookupsourceItemsRuleContext>() { ResultItemId = page2.ID.ToString() }; action.Apply(ctx); ctx.IsAborted.Should().BeTrue(); } }
public void ReplacesToken() { using (var db = new Db() { new DbItem("Home") { new DbItem("page1"), new DbItem("page2") } }) { var home = db.GetItem("/sitecore/content/home"); var page1 = db.GetItem("/sitecore/content/home/page1"); var page2 = db.GetItem("/sitecore/content/home/page2"); var args = new GetLookupSourceItemsArgs() { Item = page1, Source = "{ThisPage}/afolder" }; var ctx = new GetLookupsourceItemsRuleContext(args); var action = new ReplaceTokenWithItemPathAction <GetLookupsourceItemsRuleContext>() { Token = "ThisPage", NewItemId = page2.ID.ToString() }; action.Apply(ctx); ctx.Args.Source.Should().BeEquivalentTo("/sitecore/content/home/page2/afolder"); } }
public void Process(GetLookupSourceItemsArgs args) { if (args.Source.Contains(Constants.Tokens.WeBlogContext)) { args.Source = TokenReplacer.ResolveContextTokens(args.Source, args.Item); } }
public GetLookupsourceItemsRuleContext(GetLookupSourceItemsArgs args) { Settings = new RulesSettings(); Args = args; Item = args.Item; }
public void SetsContextItem() { using (var db = new Db() { new DbItem("page1"), new DbItem("page2") }) { var page1 = db.GetItem("/sitecore/content/page1"); var page2 = db.GetItem("/sitecore/content/page2"); var args = new GetLookupSourceItemsArgs() { Item = page1, Source = "./*" }; var ctx = new GetLookupsourceItemsRuleContext(args); var action = new SetQueryContextItemAction <GetLookupsourceItemsRuleContext>() { NewContextItemId = page2.ID.ToString() }; action.Apply(ctx); ctx.Args.Item.ID.Should().Be(page2.ID); } }
public void Process(GetLookupSourceItemsArgs args) { if (TokenReplacer.ContainsToken(args.Source)) { args.Source = TokenReplacer.Replace(args.Source, args.Item); } }
public static NameValueCollection GetSourceString(string itemId, string itemLanguage, string source) { var current = Sitecore.Context.ContentDatabase.GetItem(new ID(itemId), Language.Parse(itemLanguage)); var lookupSourceItemsArgs = new GetLookupSourceItemsArgs { Item = current, Source = source }; try { using (new LongRunningOperationWatcher(1000, "getLookupSourceItems pipeline[item={0}, source={1}]", current.Paths.Path, source)) { CorePipeline.Run("getLookupSourceItems", lookupSourceItemsArgs); } } catch (Exception ex) { throw new LookupSourceException(source, ex); } var parsedSource = HttpUtility.ParseQueryString(lookupSourceItemsArgs.Source.ToLower()); return(parsedSource); }
public void DetectsItemFieldTokenWithoutFieldName() { using (var db = new Db() { new DbItem("page1"), new DbItem("page2") }) { var page1 = db.GetItem("/sitecore/content/page1"); var args = new GetLookupSourceItemsArgs() { Item = page1, Source = "{ItemField:FullName}" }; var context = new GetLookupsourceItemsRuleContext(args); var condition = new QueryContainsTokenCondition <GetLookupsourceItemsRuleContext>() { Token = "ItemField" }; var ruleStack = new RuleStack(); condition.Evaluate(context, ruleStack); ruleStack.Should().HaveCount(1); ruleStack.Pop().Should().Be(true); } }
public void MatchesToken() { using (var db = new Db() { new DbItem("page1"), new DbItem("page2") }) { var page1 = db.GetItem("/sitecore/content/page1"); var page2 = db.GetItem("/sitecore/content/page2"); var args = new GetLookupSourceItemsArgs() { Item = page1, Source = "{Home}/page1" }; var context = new GetLookupsourceItemsRuleContext(args); var condition = new QueryContainsTokenCondition <GetLookupsourceItemsRuleContext>() { Token = "Home" }; var ruleStack = new RuleStack(); condition.Evaluate(context, ruleStack); ruleStack.Should().HaveCount(1); ruleStack.Pop().Should().Be(true); } }
public void Process(GetLookupSourceItemsArgs args) { if (!args.Item.InheritsFrom(SitecoreIDs.StandardRenderingParametersTemplateId)) { return; } var url = WebUtil.GetQueryString(); if (string.IsNullOrWhiteSpace(url)) { return; } try { var parameters = FieldEditorOptions.Parse(new UrlString(url)).Parameters; var currentItemUri = parameters["contentitem"]; if (string.IsNullOrEmpty(currentItemUri)) { return; } var contentItemUri = new ItemUri(currentItemUri); var contextItem = Database.GetItem(contentItemUri); args.Item = contextItem; } catch (Exception ex) { Sitecore.Diagnostics.Log.Error(ex.Message, ex, this); } }
public void Process(GetLookupSourceItemsArgs args) { if (!args.Source.StartsWith(DependentUponTag)) { return; } var fieldName = GetFieldName(args.Source); args.Source = GetDataSource(args.Item[fieldName]); }
public void Process(GetLookupSourceItemsArgs args) { try { _runner.RunGlobalRules("Get Lookup Source Items", args.Item.Database, new GetLookupsourceItemsRuleContext(args)); } catch (Exception ex) { Log.Error(ex.Message, ex, this); } }
/// <summary> /// Process Method /// </summary> /// <param name="args"> /// The args. /// </param> public void Process(GetLookupSourceItemsArgs args) { Assert.ArgumentNotNull(args, "args"); if (args.Source.StartsWith("lucene:")) { var itemArray = RunEnumeration(args.Source, args.Item); if (itemArray.IsNotNull() && (itemArray.Length > 0)) { args.Result.AddRange(itemArray); } args.AbortPipeline(); } }
/// <summary> /// Process Method /// </summary> /// <param name="args"> /// The args. /// </param> public void Process(GetLookupSourceItemsArgs args) { Assert.ArgumentNotNull(args, "args"); if (args.Source.StartsWith("code:")) { var itemArray = RunEnumeration(args.Source, args.Item); if (itemArray.IsNotNull() && (itemArray.Length > 0)) { args.Result.AddRange(itemArray); } args.AbortPipeline(); } }
public void Process(GetLookupSourceItemsArgs args) { Assert.ArgumentNotNull(args, "args"); if (IsScripted(args.Source)) { var items = new ItemList(); var source = GetScriptedQueries(args.Source, args.Item, items); args.Result.AddRange(items.ToArray()); if (string.IsNullOrEmpty(source)) { args.AbortPipeline(); } } }
public void Process(GetLookupSourceItemsArgs args) { Assert.ArgumentNotNull(args, "args"); if (IsScripted(args.Source)) { var items = new ItemList(); string source = GetScriptedQueries(args.Source, args.Item, items); args.Result.AddRange(items.ToArray()); if (string.IsNullOrEmpty(source)) { args.AbortPipeline(); } } }
public void Process(GetLookupSourceItemsArgs args) { if (!args.Source.Contains(scapePrefix)) { return; } Item contextItem; // Only goes ahead if this is a Parameters Template if (args.Item.Template.BaseTemplates.Where(bt => bt.ID == BaseParameterTemplate).Any()) { // This whole block is to get Context Item string url = WebUtil.GetQueryString(); if (string.IsNullOrWhiteSpace(url)) { args.Source = String.Empty; return; } FieldEditorParameters parameters = null; try { parameters = FieldEditorOptions.Parse(new UrlString(url)).Parameters; } catch (Exception) { } if (parameters == null) { args.Source = String.Empty; return; } var currentItemId = parameters["contentitem"]; if (string.IsNullOrEmpty(currentItemId)) { args.Source = String.Empty; return; } ItemUri contentItemUri = new ItemUri(currentItemId); contextItem = Database.GetItem(contentItemUri); } else { contextItem = args.Item; } // Now to the custom (site-specific) parameters var sourceName = args.Source.Replace(scapePrefix, "").Trim(); args.Source = provider.GetSource(contextItem, sourceName); }
public virtual void Process(GetLookupSourceItemsArgs args) { using (new TraceOperation("Run ReplaceLookupSourceQueryTokens.")) { var query = args.Source; query = ReplaceWebsiteToken(query, args.Item); query = ReplaceHomeItemToken(query, args.Item); query = ReplaceThemeItemToken(query, args.Item); query = ReplaceItemFieldValueToken(query, args.Item); args.Source = query; } }
public void Process(GetLookupSourceItemsArgs args) { try { using (new TraceOperation("Run GetLookupSourceItems rules.")) { _runner.RunGlobalRules(RuleIDs.GetLookupSourceItemsGlobalRulesRootId, args.Item.Database, new GetLookupsourceItemsRuleContext(args)); } } catch (Exception ex) { Log.Error(ex.Message, ex, this); } }
public void ReplacesHomeToken() { using (var db = GetDb()) { var page = db.GetItem("/sitecore/content/Website/Home/Page1"); var processor = new ReplaceLookupSourceQueryTokens(); var args = new GetLookupSourceItemsArgs { Item = page, Source = "{Home}/Page1" }; processor.Process(args); args.Source.Should().Be("/sitecore/content/Website/Home/Page1"); } }
public void Process(GetLookupSourceItemsArgs args) { //should we care? if (HasLookup(args.Source)) { var url = WebUtil.GetQueryString(); if (string.IsNullOrWhiteSpace(url)) { return; } var fieldEditorOptions = FieldEditorOptions.Parse(new UrlString(url)); var parameters = fieldEditorOptions.Parameters; var currentItemId = parameters[Constants.FieldEditor.RenderingParameters.ContentItem]; if (string.IsNullOrEmpty(currentItemId)) { return; } // get the context item. var contentItemUri = new ItemUri(currentItemId); var contextItem = Database.GetItem(contentItemUri); // get all item fields, filter out standard fields and order. maybe group by section in future? contextItem.Fields.ReadAll(); var itemFields = contextItem.Fields.Where(f => !f.Name.StartsWith("__")).OrderBy(f => f.DisplayName); foreach (Field field in itemFields) { // check if we support the field type if (IsSupportedField(field)) { args.Result.Add(field.InnerItem); } } // if no other queries to be served, no need to continue pipeline args.AbortPipeline(); } }
public void Process(GetLookupSourceItemsArgs args) { Assert.ArgumentNotNull(args, "args"); if (args.Source.StartsWith("code:")) { Item[] itemArray; string query = args.Source; itemArray = RunEnumeration(query, args.Item); if ((itemArray != null) && (itemArray.Length > 0)) { args.Result.AddRange(itemArray); } args.AbortPipeline(); } }
public void ReplacesItemFieldValueToken() { using (var db = GetDb()) { var page = db.GetItem("/sitecore/content/Website/Home/Page1"); var processor = new ReplaceLookupSourceQueryTokens(); page["FieldName"].Should().BeEquivalentTo("FieldValue"); var args = new GetLookupSourceItemsArgs { Item = page, Source = "{ItemField:FieldName}/Page1" }; processor.Process(args); args.Source.Should().Be("FieldValue/Page1"); } }
public void Process(GetLookupSourceItemsArgs args) { var source = args.Source; if (!source.IsNullOrEmpty()) { _datasourceItem = args.Item.Database.GetItem(source); _contextItem = args.Item; } try { var rules = RuleFactory.GetRules <ModuleOptionsRuleContext>(new[] { _datasourceItem }, ModuleTypeRulesField).Rules; if (rules.Any()) { var moduleOptionsRuleContext = EvaluateRules(rules); var optionsToAllow = moduleOptionsRuleContext.OptionsToAllow; var optionsToBlock = moduleOptionsRuleContext.OptionsToBlock; var optionIdsToBlock = optionsToBlock.Select(x => x.ID); var optionsToRemove = args.Result.Cast <Item>().Where(oi => optionIdsToBlock.Contains(oi.ID)).ToList(); foreach (var optionToRemove in optionsToRemove) { args.Result.Remove(optionToRemove); Log.Info(string.Format("GetAllowedOptions: {0} removed for {1}", optionToRemove.Name, _contextItem.Name), this); } foreach (var optionToAllow in optionsToAllow) { if (!args.Result.ContainsID(optionToAllow.ID)) { args.Result.Add(optionToAllow); Log.Info(string.Format("GetAllowedOptions: {0} allowed for {1}", optionToAllow.Name, _contextItem.Name), this); } } } } catch (Exception ex) { Log.Error("Error in GetAllowedOptions", ex, this); } }
public GetLookupsourceItemsRuleContext(GetLookupSourceItemsArgs args) { Args = args; Item = args.Item; }
public override void Process(GetLookupSourceItemsArgs args) { args.Source = ReplaceThemeToken(args.Source, args.Item); }