Using custom field types

Good afternoon. I was wondering. I am in need of creating a custom field type. Even following the tutorial it shows all the way up to building the new field. It seems to be working fine but I do not really know how to use it after that. Not in code and I cant seem to find it anywhere in the back office.

I can from any c# class do the following:
var test = new FieldTypes.CustomTextFieldTypeMetadata();
However attaching it to a template is another matter. I realise I am missing something here. Any ideas?

Litium version: 7.2.3

You need to create a field definition using your custom field type, then you can add it to a template. If you go to the Settings > the module you want to use the field in > Fields, you can create the field by clicking New and selecting your custom field type in the list. Then you can go to Field Templates, edit a template and add the newly created field.

Programmatically, you create the field with something like (inject the services in the constructor):

var field = new FieldDefinition<ProductArea>("MyField", "CustomFieldTypeName")
{
	CanBeGridColumn = false,
	CanBeGridFilter = false,
	MultiCulture = false,
};

using (_securityContextService.ActAsSystem())
{
	_fieldDefinitionService.Create(field);
}

Then it depends on if you want to create a new template or add it to an existing one. In the Accelerator you can check out Definitions for some more examples.

You can also look att

ProductsDefinitionSetup.cs

to see how the initial setup is created.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.