using System.Collections.Generic;
using Newtonsoft.Json;
using Umbraco.Core.IO;
using Umbraco.Core.Manifest;
namespace Umbraco.Core.PropertyEditors
{
///
/// Defines a pre value editable field
///
public class PreValueField
{
private string _view;
///
/// Standard constructor
///
public PreValueField()
{
Validators = new List();
Config = new Dictionary();
//check for an attribute and fill the values
var att = GetType().GetCustomAttribute(false);
if (att != null)
{
Name = att.Name;
Description = att.Description;
HideLabel = att.HideLabel;
Key = att.Key;
View = att.View;
}
}
///
/// Constructor used to set validators instead of adding them later
///
///
public PreValueField(params IPropertyValidator[] validators)
: this()
{
foreach (var v in validators)
{
Validators.Add(v);
}
}
///
/// The name to display for this pre-value field
///
[JsonProperty("label", Required = Required.Always)]
public string Name { get; set; }
///
/// The description to display for this pre-value field
///
[JsonProperty("description")]
public string Description { get; set; }
///
/// Specifies whether to hide the label for the pre-value
///
[JsonProperty("hideLabel")]
public bool HideLabel { get; set; }
///
/// The key to store the pre-value against
///
[JsonProperty("key", Required = Required.Always)]
public string Key { get; set; }
///
/// Defines the view to use for the editor, this can be one of 3 things:
/// * the full virtual path or
/// * the relative path to the current Umbraco folder
/// * a simple view name which will map to the views/prevalueeditors/{view}.html
///
[JsonProperty("view", Required = Required.Always)]
public string View
{
get => _view;
set => _view = IOHelper.ResolveVirtualUrl(value);
}
///
/// A collection of validators for the pre value field
///
[JsonProperty("validation", ItemConverterType = typeof(ManifestValidatorConverter))]
public List Validators { get; private set; }
///
/// This allows for custom configuration to be injected into the pre-value editor
///
[JsonProperty("config")]
public IDictionary Config { get; set; }
}
}