Files
Umbraco-CMS/src/Umbraco.Core/PropertyEditors/ConfigurationField.cs

112 lines
3.5 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
2018-01-20 12:09:15 +01:00
using System.Linq;
using Newtonsoft.Json;
2018-01-24 11:44:44 +01:00
using Umbraco.Core.IO;
2018-01-20 12:09:15 +01:00
namespace Umbraco.Core.PropertyEditors
{
/// <summary>
/// Represents a datatype configuration field for editing.
/// </summary>
2018-01-24 11:44:44 +01:00
public class ConfigurationField
2018-01-20 12:09:15 +01:00
{
2018-01-24 11:44:44 +01:00
private string _view;
2018-01-20 12:09:15 +01:00
/// <summary>
2018-01-24 11:44:44 +01:00
/// Initializes a new instance of the <see cref="ConfigurationField"/> class.
2018-01-20 12:09:15 +01:00
/// </summary>
2018-01-24 11:44:44 +01:00
public ConfigurationField()
: this(new List<IValueValidator>())
2018-01-20 12:09:15 +01:00
{ }
/// <summary>
2018-01-24 11:44:44 +01:00
/// Initializes a new instance of the <see cref="ConfigurationField"/> class.
2018-01-20 12:09:15 +01:00
/// </summary>
2018-01-24 11:44:44 +01:00
public ConfigurationField(params IValueValidator[] validators)
2018-01-20 12:09:15 +01:00
: this(validators.ToList())
{ }
/// <summary>
2018-01-24 11:44:44 +01:00
/// Initializes a new instance of the <see cref="ConfigurationField"/> class.
2018-01-20 12:09:15 +01:00
/// </summary>
2018-01-24 11:44:44 +01:00
private ConfigurationField(List<IValueValidator> validators)
2018-01-20 12:09:15 +01:00
{
Validators = validators;
Config = new Dictionary<string, object>();
// fill details from attribute, if any
2018-01-24 11:44:44 +01:00
var attribute = GetType().GetCustomAttribute<ConfigurationFieldAttribute>(false);
2018-01-20 12:09:15 +01:00
if (attribute == null) return;
Name = attribute.Name;
Description = attribute.Description;
HideLabel = attribute.HideLabel;
Key = attribute.Key;
View = attribute.View;
}
2018-01-24 11:44:44 +01:00
/// <summary>
/// Gets or sets the key of the field.
/// </summary>
[JsonProperty("key", Required = Required.Always)]
public string Key { get; set; }
2018-01-20 12:09:15 +01:00
/// <summary>
/// Gets or sets the name of the field.
/// </summary>
[JsonProperty("label", Required = Required.Always)]
public string Name { get; set; }
2018-01-24 11:44:44 +01:00
/// <summary>
/// Gets or sets the property name of the field.
/// </summary>
[JsonIgnore]
public string PropertyName { get; set; }
/// <summary>
2019-01-22 18:03:39 -05:00
/// Gets or sets the property CLR type of the field.
/// </summary>
[JsonIgnore]
public Type PropertyType { get; set; }
2018-01-20 12:09:15 +01:00
/// <summary>
/// Gets or sets the description of the field.
/// </summary>
[JsonProperty("description")]
public string Description { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to hide the label of the field.
/// </summary>
[JsonProperty("hideLabel")]
public bool HideLabel { get; set; }
/// <summary>
/// Gets or sets the view to used in the editor.
/// </summary>
/// <remarks>
/// <para>Can be the full virtual path, or the relative path to the Umbraco folder,
/// or a simple view name which will map to ~/Views/PreValueEditors/{view}.html.</para>
/// </remarks>
[JsonProperty("view", Required = Required.Always)]
2018-01-24 11:44:44 +01:00
public string View
{
get => _view;
set => _view = IOHelper.ResolveVirtualUrl(value);
}
2018-01-20 12:09:15 +01:00
/// <summary>
/// Gets the validators of the field.
/// </summary>
2018-01-24 11:44:44 +01:00
[JsonProperty("validation")]
public List<IValueValidator> Validators { get; }
2018-01-20 12:09:15 +01:00
/// <summary>
/// Gets or sets extra configuration properties for the editor.
/// </summary>
[JsonProperty("config")]
public IDictionary<string, object> Config { get; set; }
}
}