Luuk Peters (ProudNerds)
01/10/2025, 3:52 PMcsharp
var configuration = new SliderConfiguration
{
EnableRange = false,
MinimumValue = new decimal(0),
MaximumValue = new decimal(1),
}
var editorAlias = Umbraco.Cms.Core.Constants.PropertyEditors.Aliases.Slider;
//How to get the editor from the alias is not important
//serializer is an injected IConfigurationEditorJsonSerializer
var newType = new DataType(editor, serializer)
{
DatabaseType = _databaseType ?? ValueStorageType.Ntext,
CreateDate = DateTime.Now,
CreatorId = -1,
Name = _dataTypeName,
Configuration = configuration
};
In this case, Configuration is an object?. And Umbraco has models (like the SliderConfiguration) for the configuration of the editor associated with the datatype. However, things change a little (but enough) in Umbraco 15:
Configuration is now ConfigurationData and no longer a object?, but a Dictionary.
Problem 1: I assume that the dictionary is a collection where the string is a property name and the object it's value. However, I'm not sure because I can't find any documentation on it. Is that's the case, what do I need to use as the keys? I mean, the SliderConfiguration class has some annotations, do I need to use these as key?
csharp
public class SliderConfiguration
{
[ConfigurationField("enableRange")]
public bool EnableRange { get; set; }
[ConfigurationField("minVal")]
public decimal MinimumValue { get; set; }
[ConfigurationField("maxVal")]
public decimal MaximumValue { get; set; }
}
Problem 2 is that I have a perfectly good strong typed model. I don't want to create a dictionary myself and trying to figure out what keys to use. I think there should be some converter/parser that could create the dictionary of my model. Any thoughts?Sebastiaan
01/10/2025, 4:00 PMLuuk Peters (ProudNerds)
01/10/2025, 4:01 PMSebastiaan
01/10/2025, 4:04 PMSebastiaan
01/10/2025, 4:05 PMSebastiaan
01/10/2025, 4:05 PMLuuk Peters (ProudNerds)
01/10/2025, 4:05 PMSebastiaan
01/10/2025, 4:06 PMSebastiaan
01/10/2025, 4:06 PMSebastiaan
01/10/2025, 4:07 PMSebastiaan
01/10/2025, 4:09 PMdotnet new umbraco-extension
to start with the boilerplate stuff is here https://kjac.dev/posts/rebuilding-a-package-for-umbraco-15/ instead of making whatever Ken is making, you can move to https://docs.umbraco.com/umbraco-cms/tutorials/creating-a-property-editorSebastiaan
01/10/2025, 4:12 PMLuuk Peters (ProudNerds)
01/10/2025, 4:17 PMSebastiaan
01/10/2025, 4:19 PMLuuk Peters (ProudNerds)
01/10/2025, 4:21 PMLuuk Peters (ProudNerds)
01/10/2025, 4:22 PMSebastiaan
01/10/2025, 4:23 PMLuuk Peters (ProudNerds)
01/10/2025, 4:24 PMSebastiaan
01/10/2025, 4:28 PMLuuk Peters (ProudNerds)
01/13/2025, 8:25 AMcsharp
IConfigurationEditorJsonSerializer serializer; //Injected
PropertyEditorCollection propertyEditorCollection; //Injected
var editorAlias = Umbraco.Cms.Core.Constants.PropertyEditors.Aliases.Slider;
if (!propertyEditorCollection.TryGet(editorAlias , out dataEditor))
return;
var configuration = new SliderConfiguration
{
EnableRange = false,
MinimumValue = new decimal(0),
MaximumValue = new decimal(1),
}
var configurationDictionary = editor?.GetConfigurationEditor().FromConfigurationObject(_configuration, serializer);
var newType = new DataType(dataEditor, serializer)
{
DatabaseType = _databaseType ?? ValueStorageType.Ntext,
CreateDate = DateTime.Now,
CreatorId = -1,
Name = _dataTypeName,
};
//Because configurationDictionary is nullable, I handle it seperately, because the configurationData parameter on the constructor does not allow nullables.
if (configurationDictionary != null)
newType.ConfigurationData = configurationDictionary;
Sebastiaan
01/13/2025, 9:11 AM