Add a field type converter
Sitecore CMP uses mappings to map items between Sitecore Content Hub and Sitecore. The conversion works together with field mapping Items that map Entity fields to the Sitecore Item Fields by their names.
By default, the mapping conversion is configured for the following property types:
-
strings: syncs text fields to text fields in Sitecore
-
DateTime: syncs date/time to date/time fields in Sitecore.
-
DateTimeOffset: includes a DateTime value, together with an Offset property that defines the difference between the current DateTimeOffset instance's date and time and Coordinated Universal Time (UTC).
The attribute type defined in the Sitecore.Connector.CMP.config
file implements the Sitecore.Connector.CMP.Conversion.ICmpConverterMapper
interface, which is injected by DI in the cmp.importEntity
pipeline on the last SaveFieldValues
step.
You might want to map a different field, such as a title field or a subject field. For this purpose, Sitecore CMP lets you configure new field type converters.
To add a field type converter:
-
Open the
Sitecore.Connector.CMP.config
file. -
Add your custom field type converter to the
converters
section. The field type converter must contain the following attributes:-
propertyDefinitionType
: can contain only inheritors of theStylelabs.M.Sdk.Contracts.Base.IPropertyDefinition
interface -
type
: can only contain type names that inherit theSitecore.Connector.CMP.Conversion.IPropertyValueConverter
interface.
For example:
RequestResponse<cmp.fieldConverterMapper type="Sitecore.Connector.CMP.Conversion.CmpConverterMapper, Sitecore.Connector.CMP" resolve="true"> <converters hint="raw:AddConverter"> <!-- propertyDefinitionType - can only contain type names that inherit Stylelabs.M.Sdk.Contracts.Base.IPropertyDefinition interface. type - can only contain type names that inherit Sitecore.Connector.CMP.Conversion.IPropertyValueConverter interface. --> <add propertyDefinitionType="Stylelabs.M.Sdk.Models.Base.PropertyDefinitions.StringPropertyDefinition, Stylelabs.M.Sdk" type="Sitecore.Connector.CMP.Conversion.StringPropertyValueConverter, Sitecore.Connector.CMP"/> <add propertyDefinitionType="Stylelabs.M.Sdk.Models.Base.PropertyDefinitions.DateTimePropertyDefinition, Stylelabs.M.Sdk" type="Sitecore.Connector.CMP.Conversion.NullableDateTimePropertyValueConverter, Sitecore.Connector.CMP"/> <add propertyDefinitionType="Stylelabs.M.Sdk.Models.Base.PropertyDefinitions.DateTimeOffsetPropertyDefinition, Stylelabs.M.Sdk" type="Sitecore.Connector.CMP.Conversion.NullableDateTimeOffsetPropertyValueConverter, Sitecore.Connector.CMP"/> </converters> </cmp.fieldConverterMapper>
-