Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Paul Seal 524 posts 2889 karma points MVP 6x c-trib
    Jan 29, 2023 @ 13:01
    Paul Seal
    0

    Creating a Block List Data Type Programmatically

    I am getting an error when trying to create a block list data type programmatically.

    {"ExceptionMessage":"Value of type BlockListConfiguration cannot be a configuration for editor Umbraco.BlockList, expecting. (Parameter 'value')"
    

    The issue is when I am trying to set the configuration.

    Please can you help me work out where I am going wrong?

    Here is my code:

    public void CreateDataType(string name)
    {
        var newDataType = new DataType(
            new DataEditor(_dataValueEditorFactory)
            {
                Alias = "Umbraco.BlockList"
            }, _configurationEditorJsonSerializer)
        {
            Name = name,
            Configuration = new BlockListConfiguration
            {
                Blocks = new[]
                {
                    new BlockListConfiguration.BlockConfiguration
                    {
                        ContentElementTypeKey = new Guid("08e05150-1fe7-4810-96d2-cc0b9fd77a40"),
                        SettingsElementTypeKey = new Guid("55876948-ac8b-440f-bbca-19ac2bb18189"),
                        Label = "{{ !$title || $title == '' ? 'Test ' + $index : $title }}",
                        EditorSize = "medium",
                        ForceHideContentEditorInOverlay = false,
                        Stylesheet = "",
                        View = "",
                        IconColor = "#ffffff",
                        BackgroundColor = "#1b264f"
                    },
                },
                MaxPropertyWidth = "100%",
                UseSingleBlockMode = false,
                UseLiveEditing = false,
                UseInlineEditingAsDefault = false,
                ValidationLimit = new BlockListConfiguration.NumberRange()
                {
                    Min = 0,
                    Max = 10
                }
            }
        };
    
        _dataTypeService.Save(newDataType);
    }
    

    Kind regards

    Paul

  • Sander Los 27 posts 160 karma points
    Jan 30, 2023 @ 06:04
    Sander Los
    0

    Hi Paul,

    that is really weird. I get the same error when setting the configuration in the way you describe.

    I tried a couple of things and when I saved the DataType first (without the configuration) and set the configuration afterward (with the same values), the configuration is being set correctly. (below ugly/verbose code used for testing purposes)

    var config = new BlockListConfiguration{...}
    _dataTypeService.Save(newDataType);
    var testType = _dataTypeService.GetDataType(name);
    testType.Configuration = config;
    _dataTypeService.Save(testType);
    

    I hope someone else has some good insights on why it does not work when constructing it from scratch.

  • Paul Seal 524 posts 2889 karma points MVP 6x c-trib
    Jan 30, 2023 @ 07:22
    Paul Seal
    0

    Hi

    I got it working. My friends Anders and Callum helped me in the MVP slack group.

    I’ll update this post later with the solution.

    Thanks

    Paul

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Oct 02, 2023 @ 17:00
    Steve Morgan
    0

    Hi Paul,

    I'm trying to update a datatype configuration and wondered if you have this code to hand as it might give me the clues I need to solve a start node ID update problem I have?

    Kind regards

    Steve

  • Paul Seal 524 posts 2889 karma points MVP 6x c-trib
    Oct 02, 2023 @ 17:52
  • Steve Morgan 1346 posts 4453 karma points c-trib
    Oct 03, 2023 @ 10:00
    Steve Morgan
    0

    Thanks, very useful.

    Looks like my approach is fine. I'm struggling to update an existing data type rather than create a new one.

Please Sign in or register to post replies

Write your reply to:

Draft