using System.Collections.Generic; using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { /// /// A property editor to allow multiple selection of pre-defined items /// /// /// Due to maintaining backwards compatibility this data type stores the value as a string which is a comma separated value of the /// ids of the individual items so we have logic in here to deal with that. /// [PropertyEditor(Constants.PropertyEditors.DropdownlistMultiplePublishKeysAlias, "Dropdown list multiple, publish keys", "dropdown")] public class DropDownMultipleWithKeysPropertyEditor : DropDownPropertyEditor { protected override ValueEditor CreateValueEditor() { return new PublishValuesMultipleValueEditor(true, base.CreateValueEditor()); } protected override PreValueEditor CreatePreValueEditor() { return new DropDownMultiplePreValueEditor(); } /// /// A pre-value editor for the 'drop down list multiple' property editor that ensures that 'multiple' is saved for the config in the db but is not /// rendered as a pre-value field. /// /// /// This is mostly to maintain backwards compatibility with old property editors. Devs can now simply use the Drop down property editor and check the multiple pre-value checkbox /// internal class DropDownMultiplePreValueEditor : ValueListPreValueEditor { public DropDownMultiplePreValueEditor() { //add the multiple field, we'll make it hidden so it is not seen in the pre-value editor Fields.Add(new PreValueField { Key = "multiple", Name = "multiple", View = "hidden", HideLabel = true }); } /// /// Always /// /// /// /// public override IDictionary FormatDataForEditor(IDictionary defaultPreVals, PreValueCollection persistedPreVals) { var returnVal = base.FormatDataForEditor(defaultPreVals, persistedPreVals); //always add the multiple param to true returnVal["multiple"] = "1"; return returnVal; } } } }