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.
This commit is contained in:
Matteo Piovanelli 2024-02-29 19:38:48 +01:00 committed by GitHub
parent 90dc993e83
commit c7d10fd0be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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>("ContentPickerField")
.Token("Content", (Func<ContentPickerField, object>)(field => field.Ids[0]))
.Chain("Content", "Content", (Func<ContentPickerField, object>)(field => _contentManager.Get(field.Ids[0])))
.Chain("Content", "Content", (Func<ContentPickerField, object>)(field => {
var id = field.Ids.Any() ? field.Ids[0] : 0;
return _contentManager.Get(id);
}))
;
}
}