From c7d10fd0bea36c7279cfe870f4bce25d3d4104a7 Mon Sep 17 00:00:00 2001 From: Matteo Piovanelli Date: Thu, 29 Feb 2024 19:38:48 +0100 Subject: [PATCH] When chaining tokens, if nothing was selected in a CPF, evaluation would log (#8763) and error because it would seek an item out of the range of the array. --- .../Modules/Orchard.ContentPicker/Tokens/FieldTokens.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Orchard.Web/Modules/Orchard.ContentPicker/Tokens/FieldTokens.cs b/src/Orchard.Web/Modules/Orchard.ContentPicker/Tokens/FieldTokens.cs index f10bcfb52..341b15eaa 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentPicker/Tokens/FieldTokens.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentPicker/Tokens/FieldTokens.cs @@ -3,6 +3,7 @@ using Orchard.ContentManagement; using Orchard.Events; using Orchard.ContentPicker.Fields; using Orchard.Localization; +using NHibernate.Util; namespace Orchard.ContentPicker.Tokens { public interface ITokenProvider : IEventHandler { @@ -28,7 +29,10 @@ namespace Orchard.ContentPicker.Tokens { public void Evaluate(dynamic context) { context.For("ContentPickerField") .Token("Content", (Func)(field => field.Ids[0])) - .Chain("Content", "Content", (Func)(field => _contentManager.Get(field.Ids[0]))) + .Chain("Content", "Content", (Func)(field => { + var id = field.Ids.Any() ? field.Ids[0] : 0; + return _contentManager.Get(id); + })) ; } }