D_Inventor
05/13/2024, 8:26 AMIDataListSource
and IDataSourceValueConverter
. This works for my Umbraco 10 site, I get the picker and the picked items are returned as a list of nullable integers.
After upgrading to Umbraco 13, the picker still works, but the values are no longer converted to nullabel integers. When I run the modelsbuilder, all nullable integer properties are replaced with strings. Is there something I'm missing between U10 and U13 so my custom data list keeps working? Here is the code for reference:
csharp
public class TaxonomyDataList : IDataListSource, IDataSourceValueConverter
{
private readonly ITaxonomyService _taxonomyService;
// 👇 The constructor here is called when I debug
public TaxonomyDataList(ITaxonomyService taxonomyService)
{
_taxonomyService = taxonomyService;
}
// --trivial properties omitted for brevity--
// 👇 This part is NOT called
public object ConvertValue(Type type, string value)
{
return int.TryParse(value, out var intValue) ? intValue : null!;
}
public IEnumerable<DataListItem> GetItems(Dictionary<string, object> config)
{
var items = new List<DataListItem>();
// HACK: it's required to run an async task inside a sync context
var collection = Task.Run(() => _taxonomyService.List(tagsOnly: true)).Result;
foreach ( var item in collection.Words)
{
items.Add(new DataListItem
{
Name = item.Word,
Value = item.Id.ToString()
});
}
return items;
}
// 👇 This part is NOT called
public Type GetValueType(Dictionary<string, object> config)
{
return typeof(Nullable<int>);
}
}
D_Inventor
05/13/2024, 2:05 PM