[SOLVED] Contentment datalist source with value co...
# help-with-umbraco
d
I am using Contentment 4.6.1 (but also tried 4.7.0) to create a custom picker. The items have an integer id, so I implemented both
IDataListSource
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:
Copy code
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>);
    }
}
It turns out that this had already broken earlier! I had moved my data list source to a different assembly and that broke the configuration in the backoffice!
12 Views