I'm currently in the process of creating a plugin and want to create document types and data types programatically. I've figured out the document type part, or I'm at least on the right track but have run into an issue created a new data type.
I've figured out how to create a new data type based on existing propertyEditors - I've created a data type based on the repeatable strings property editor but can't quite figure out how to set configuration values. Here's my code:
var dataTypeContainer = Services.DataTypeService.CreateContainer(-1, "Umbraco Rss Feeds");
if (dataTypeContainer.Success)
{
var dataType = new DataTypeDefinition(dataTypeContainer.Result.Entity.Id, "Umbraco.MultipleTextstring");
dataType.Name = "Allowed Content Types";
Services.DataTypeService.Save(dataType);
}
So first I'm creating a container/folder to hold my new data type which works fine. Then if that's successful, I go on to create a new data type based on the Umbraco.MultipleTextstring property editor. This all works but I want to further customise this new data type by setting the Maximum and Minimum configuration values.
I've been through the properties available to me through code completion but can't find anything to help me set the values.
I've also started to question if it's even possible to do it this way. I found code in the umbraco repository that I'm wondering if I need to hook into/extend but still can't see anything for the configuration.
Creating a Custom Data Type Programatically
Hi,
I'm currently in the process of creating a plugin and want to create document types and data types programatically. I've figured out the document type part, or I'm at least on the right track but have run into an issue created a new data type.
I've figured out how to create a new data type based on existing propertyEditors - I've created a data type based on the repeatable strings property editor but can't quite figure out how to set configuration values. Here's my code:
So first I'm creating a container/folder to hold my new data type which works fine. Then if that's successful, I go on to create a new data type based on the
Umbraco.MultipleTextstring
property editor. This all works but I want to further customise this new data type by setting theMaximum
andMinimum
configuration values.I've been through the properties available to me through code completion but can't find anything to help me set the values.
I've also started to question if it's even possible to do it this way. I found code in the umbraco repository that I'm wondering if I need to hook into/extend but still can't see anything for the configuration.
Thanks in advance for any help,
Ben
Hi Ben,
if I am correct I think the
DataTypeDefinition
object has a property calledAdditionalData
which is aDictionary<string, object>
type.There you can access the
Minimum
andMaximum
configuration properties.Hope this helps!
/Michaël
Hi Ben,
did you had the chance to solve your issue?
Could you report back and share this on the community?
/Michaël
Actually I did!
You need to save the data type along with prevalues. For example, to set a single image picker, I've used the following code:
Hope it helps anyone else who might stumble upon the same issue.
is working on a reply...