Class DataValueEditor
Represents a value editor.
Inheritance
Namespace: Umbraco.Core.PropertyEditors
Assembly: Umbraco.Core.dll
Syntax
public class DataValueEditor : IDataValueEditor
Constructors
View SourceDataValueEditor()
Initializes a new instance of the DataValueEditor class.
Declaration
public DataValueEditor()
DataValueEditor(String, IValueValidator[])
Initializes a new instance of the DataValueEditor class.
Declaration
public DataValueEditor(string view, params IValueValidator[] validators)
Parameters
Type | Name | Description |
---|---|---|
System.String | view | |
IValueValidator[] | validators |
DataValueEditor(DataEditorAttribute)
Initializes a new instance of the DataValueEditor class.
Declaration
public DataValueEditor(DataEditorAttribute attribute)
Parameters
Type | Name | Description |
---|---|---|
DataEditorAttribute | attribute |
Properties
View SourceConfiguration
Gets or sets the value editor configuration.
Declaration
public virtual object Configuration { get; set; }
Property Value
Type | Description |
---|---|
System.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 |
HideLabel
If this is true than the editor will be displayed full width without a label
Declaration
public bool HideLabel { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsReadOnly
Set this to true if the property editor is for display purposes only
Declaration
public virtual bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
RequiredValidator
Gets the validator used to validate the special property type -level "required".
Declaration
public virtual IValueRequiredValidator RequiredValidator { get; }
Property Value
Type | Description |
---|---|
IValueRequiredValidator |
Validators
A collection of validators for the pre value editor
Declaration
public List<IValueValidator> Validators { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.List<IValueValidator> |
ValueType
The value type which reflects how it is validated and stored in the database
Declaration
public string ValueType { get; set; }
Property Value
Type | Description |
---|---|
System.String |
View
Gets or sets the editor view.
Declaration
public string View { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
The view can be three things: (1) the full virtual path, or (2) the relative path to the current Umbraco folder, or (3) a view name which maps to views/propertyeditors/{view}/{view}.html.
Methods
View SourceConvertDbToString(PropertyType, Object, IDataTypeService)
Converts a property value to a string.
Declaration
public virtual string ConvertDbToString(PropertyType propertyType, object value, IDataTypeService dataTypeService)
Parameters
Type | Name | Description |
---|---|---|
PropertyType | propertyType | |
System.Object | value | |
IDataTypeService | dataTypeService |
Returns
Type | Description |
---|---|
System.String |
ConvertDbToXml(Property, IDataTypeService, ILocalizationService, Boolean)
Converts a property to Xml fragments.
Declaration
public IEnumerable<XElement> ConvertDbToXml(Property property, IDataTypeService dataTypeService, ILocalizationService localizationService, bool published)
Parameters
Type | Name | Description |
---|---|---|
Property | property | |
IDataTypeService | dataTypeService | |
ILocalizationService | localizationService | |
System.Boolean | published |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> |
ConvertDbToXml(PropertyType, Object, IDataTypeService)
Converts a property value to an Xml fragment.
Declaration
public XNode ConvertDbToXml(PropertyType propertyType, object value, IDataTypeService dataTypeService)
Parameters
Type | Name | Description |
---|---|---|
PropertyType | propertyType | |
System.Object | value | |
IDataTypeService | dataTypeService |
Returns
Type | Description |
---|---|
System.Xml.Linq.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 | |
System.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 |
---|---|
System.Object |
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.
ToEditor(Property, IDataTypeService, 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(Property property, IDataTypeService dataTypeService, string culture = null, string segment = null)
Parameters
Type | Name | Description |
---|---|---|
Property | property | |
IDataTypeService | dataTypeService | |
System.String | culture | |
System.String | segment |
Returns
Type | Description |
---|---|
System.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.
Validate(Object, Boolean, String)
Validates a property value.
Declaration
public IEnumerable<ValidationResult> Validate(object value, bool required, string format)
Parameters
Type | Name | Description |
---|---|---|
System.Object | value | The property value. |
System.Boolean | required | A value indicating whether the property value is required. |
System.String | format | A specific format (regex) that the property value must respect. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> |