Class DataValueEditor
Represents a value editor.
Inheritance
Namespace: Umbraco.Cms.Core.PropertyEditors
Assembly: Umbraco.Core.dll
Syntax
[DataContract]
public class DataValueEditor : IDataValueEditor
Constructors
View SourceDataValueEditor(IShortStringHelper, IJsonSerializer?)
Initializes a new instance of the DataValueEditor class.
Declaration
public DataValueEditor(IShortStringHelper shortStringHelper, IJsonSerializer? jsonSerializer)
Parameters
| Type | Name | Description |
|---|---|---|
| IShortStringHelper | shortStringHelper | |
| IJsonSerializer | jsonSerializer |
DataValueEditor(IShortStringHelper, IJsonSerializer, IIOHelper, DataEditorAttribute)
Initializes a new instance of the DataValueEditor class.
Declaration
public DataValueEditor(IShortStringHelper shortStringHelper, IJsonSerializer jsonSerializer, IIOHelper ioHelper, DataEditorAttribute attribute)
Parameters
| Type | Name | Description |
|---|---|---|
| IShortStringHelper | shortStringHelper | |
| IJsonSerializer | jsonSerializer | |
| IIOHelper | ioHelper | |
| DataEditorAttribute | attribute |
Properties
View SourceConfigurationObject
Gets or sets the value editor configuration.
Declaration
public virtual object? ConfigurationObject { get; set; }
Property Value
| Type | Description |
|---|---|
| object |
FormatValidator
Gets the validator used to validate the special property type -level "format".
Declaration
public virtual IValueFormatValidator FormatValidator { get; }
Property Value
| Type | Description |
|---|---|
| IValueFormatValidator |
IsReadOnly
Set this to true if the property editor is for display purposes only
Declaration
public virtual bool IsReadOnly { get; }
Property Value
| Type | Description |
|---|---|
| bool |
RequiredValidator
Gets the validator used to validate the special property type -level "required".
Declaration
public virtual IValueRequiredValidator RequiredValidator { get; }
Property Value
| Type | Description |
|---|---|
| IValueRequiredValidator |
SupportsReadOnly
Gets a value indicating whether the IDataValueEditor supports readonly mode
Declaration
public bool SupportsReadOnly { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Validators
A collection of validators for the pre value editor
Declaration
[DataMember(Name = "validation")]
public List<IValueValidator> Validators { get; }
Property Value
| Type | Description |
|---|---|
| List<IValueValidator> |
ValueType
The value type which reflects how it is validated and stored in the database
Declaration
[DataMember(Name = "valueType")]
public string ValueType { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
View SourceCacheContentById(IContent, IRequestCache)
Adds the specified IContent item to the request cache using its unique key.
Declaration
[Obsolete("This method is available for support of request caching retrieved entities in derived property value editors. The intention is to supersede this with lazy loaded read locks, which will make this unnecessary. Scheduled for removal in Umbraco 19.")]
protected static void CacheContentById(IContent content, IRequestCache requestCache)
Parameters
| Type | Name | Description |
|---|---|---|
| IContent | content | The content item to cache. |
| IRequestCache | requestCache | The request cache in which to store the content item. |
CacheMediaById(IMedia, IRequestCache)
Adds the specified IMedia item to the request cache using its unique key.
Declaration
[Obsolete("This method is available for support of request caching retrieved entities in derived property value editors. The intention is to supersede this with lazy loaded read locks, which will make this unnecessary. Scheduled for removal in Umbraco 19.")]
protected static void CacheMediaById(IMedia media, IRequestCache requestCache)
Parameters
| Type | Name | Description |
|---|---|---|
| IMedia | media | The media item to cache. |
| IRequestCache | requestCache | The request cache in which to store the media item. |
ConfiguredElementTypeKeys()
Declaration
public virtual IEnumerable<Guid> ConfiguredElementTypeKeys()
Returns
| Type | Description |
|---|---|
| IEnumerable<Guid> |
ConvertDbToString(IPropertyType, object?)
Converts a property value to a string.
Declaration
public virtual string ConvertDbToString(IPropertyType propertyType, object? value)
Parameters
| Type | Name | Description |
|---|---|---|
| IPropertyType | propertyType | |
| object | value |
Returns
| Type | Description |
|---|---|
| string |
ConvertDbToXml(IProperty, bool)
Converts a property to Xml fragments.
Declaration
public IEnumerable<XElement> ConvertDbToXml(IProperty property, bool published)
Parameters
| Type | Name | Description |
|---|---|---|
| IProperty | property | |
| bool | published |
Returns
| Type | Description |
|---|---|
| IEnumerable<XElement> |
ConvertDbToXml(IPropertyType, object?)
Converts a property value to an Xml fragment.
Declaration
public XNode ConvertDbToXml(IPropertyType propertyType, object? value)
Parameters
| Type | Name | Description |
|---|---|---|
| IPropertyType | propertyType | |
| object | value |
Returns
| Type | Description |
|---|---|
| XNode |
Remarks
By default, this returns the value of ConvertDbToString but ensures that if the db value type is NVarchar or NText, the value is returned as a CDATA fragment - else it's a Text fragment.
Returns an XText or XCData instance which must be wrapped in a element.
If the value is empty we will not return as CDATA since that will just take up more space in the file.
FromEditor(ContentPropertyData, object?)
A method to deserialize the string value that has been saved in the content editor to an object to be stored in the database.
Declaration
public virtual object? FromEditor(ContentPropertyData editorValue, object? currentValue)
Parameters
| Type | Name | Description |
|---|---|---|
| ContentPropertyData | editorValue | The value returned by the editor. |
| object | currentValue | The current value that has been persisted to the database for this editor. This value may be useful for how the value then get's deserialized again to be re-persisted. In most cases it will probably not be used. |
Returns
| Type | Description |
|---|---|
| object | The value that gets persisted to the database. |
Remarks
By default this will attempt to automatically convert the string value to the value type supplied by ValueType. If overridden then the object returned must match the type supplied in the ValueType, otherwise persisting the value to the DB will fail when it tries to validate the value type.
GetAndCacheContentById(Guid, IRequestCache, IContentService)
Retrieves a IContent instance by its unique identifier, using the provided request cache to avoid redundant lookups within the same request.
Declaration
[Obsolete("This method is available for support of request caching retrieved entities in derived property value editors. The intention is to supersede this with lazy loaded read locks, which will make this unnecessary. Scheduled for removal in Umbraco 19.")]
protected static IContent? GetAndCacheContentById(Guid key, IRequestCache requestCache, IContentService contentService)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | key | The unique identifier of the content item to retrieve. |
| IRequestCache | requestCache | The request-scoped cache used to store and retrieve content items for the duration of the current request. |
| IContentService | contentService | The content service used to fetch the content item if it is not found in the cache. |
Returns
| Type | Description |
|---|---|
| IContent | The IContent instance corresponding to the specified key, or null if no such content item exists. |
Remarks
This method caches content lookups for the duration of the current request to improve performance when the same content item may be accessed multiple times. This is particularly useful in scenarios involving multiple languages or blocks.
GetAndCacheMediaById(Guid, IRequestCache, IMediaService)
Retrieves a IMedia instance by its unique identifier, using the provided request cache to avoid redundant lookups within the same request.
Declaration
[Obsolete("This method is available for support of request caching retrieved entities in derived property value editors. The intention is to supersede this with lazy loaded read locks, which will make this unnecessary. Scheduled for removal in Umbraco 19.")]
protected static IMedia? GetAndCacheMediaById(Guid key, IRequestCache requestCache, IMediaService mediaService)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | key | The unique identifier of the media item to retrieve. |
| IRequestCache | requestCache | The request-scoped cache used to store and retrieve media items for the duration of the current request. |
| IMediaService | mediaService | The media service used to fetch the media item if it is not found in the cache. |
Returns
| Type | Description |
|---|---|
| IMedia | The IMedia instance corresponding to the specified key, or null if no such media item exists. |
Remarks
This method caches media lookups for the duration of the current request to improve performance when the same media item may be accessed multiple times. This is particularly useful in scenarios involving multiple languages or blocks.
IsContentAlreadyCached(Guid, IRequestCache)
Determines whether the content item identified by the specified key is present in the request cache.
Declaration
[Obsolete("This method is available for support of request caching retrieved entities in derived property value editors. The intention is to supersede this with lazy loaded read locks, which will make this unnecessary. Scheduled for removal in Umbraco 19.")]
protected static bool IsContentAlreadyCached(Guid key, IRequestCache requestCache)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | key | The unique identifier for the content item to check for in the cache. |
| IRequestCache | requestCache | The request cache in which to look for the content item. |
Returns
| Type | Description |
|---|---|
| bool | true if the content item is already cached in the request cache; otherwise, false. |
IsMediaAlreadyCached(Guid, IRequestCache)
Determines whether the media item identified by the specified key is present in the request cache.
Declaration
[Obsolete("This method is available for support of request caching retrieved entities in derived property value editors. The intention is to supersede this with lazy loaded read locks, which will make this unnecessary. Scheduled for removal in Umbraco 19.")]
protected static bool IsMediaAlreadyCached(Guid key, IRequestCache requestCache)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | key | The unique identifier for the media item to check for in the cache. |
| IRequestCache | requestCache | The request cache in which to look for the media item. |
Returns
| Type | Description |
|---|---|
| bool | true if the media item is already cached in the request cache; otherwise, false. |
ToEditor(IProperty, string?, string?)
A method used to format the database value to a value that can be used by the editor.
Declaration
public virtual object? ToEditor(IProperty property, string? culture = null, string? segment = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IProperty | property | The property. |
| string | culture | The culture. |
| string | segment | The segment. |
Returns
| Type | Description |
|---|---|
| object |
Remarks
The object returned will automatically be serialized into JSON notation. For most property editors the value returned is probably just a string, but in some cases a JSON structure will be returned.
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | ValueType was out of range. |
Validate(object?, bool, string?, PropertyValidationContext)
Validates a property value.
Declaration
public IEnumerable<ValidationResult> Validate(object? value, bool required, string? format, PropertyValidationContext validationContext)
Parameters
| Type | Name | Description |
|---|---|---|
| object | value | The property value. |
| bool | required | A value indicating whether the property value is required. |
| string | format | A specific format (regex) that the property value must respect. |
| PropertyValidationContext | validationContext | The context in which the property value is being validated. |
Returns
| Type | Description |
|---|---|
| IEnumerable<ValidationResult> |