enum to render display names in cms editor

Vote:
 

I have an enum property in the block model.

public enum TextFieldSize { Small, Standard, Large }

[BackingType(typeof(PropertyNumber))]
[EditorDescriptor(EditorDescriptorType = typeof(EnumSelector))]
[Display(
Name = "Field size",
Description = "Determines width of field displayed",
GroupName = SystemTabNames.Content,
Order = 50)]
public virtual TextFieldSize FieldSize { get; set; }

public override void SetDefaultValues(ContentType contentType)
{
base.SetDefaultValues(contentType);
FieldSize = TextFieldSize.Standard;
}

In the CMS editor, it displays the dropdown with the list of enums (Small, Standard, Large).

But I want to have display name for each. That is, instead of 'Small' I want to display as 'Small - Single Line'.

Small - Small - Single Line
Standard - Standard - Single Line
Large - Large - Multi line

I have change the enum property to
public enum TextFieldSize { [Display(Name = "Small - Single line")]Small, [Display(Name = "Standard - Single line")]Standard, [Display(Name = "Large - Multi line")]Large }

but it's does show any display names.

#152255
Aug 22, 2016 18:19
Vote:
 
[EditorDescriptor(EditorDescriptorType = typeof(EnumEditorDescriptor<SomeEnum>))]

then

public class EnumEditorDescriptor<TEnum> : EditorDescriptor where TEnum : struct, IComparable, IConvertible, IFormattable
{
    public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
    {
        SelectionFactoryType = typeof(EnumSelectionFactory<TEnum>);
        ClientEditingClass = "epi-cms/contentediting/editors/SelectionEditor";
        base.ModifyMetadata(metadata, attributes);
    }
}

public class EnumSelectionFactory<TEnum> : ISelectionFactory
{
    public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
    {
        var values = Enum.GetValues(typeof(TEnum))
                .OfType<object>()
                .Select(x=> new SelectItem { Text = "HERE-EXTRACT-TEXT-FROM-LOCALIZATION-SERVICE", Value = x});

        return values;
    }
#155046
Sep 08, 2016 11:05
Vote:
 

Maybe I'm misunderstanding this but shouldn't it be possible to put this in a language XML resource file in //languages/language node:

<property>
    <enum>
        <textfieldsize>
            <small>Small - Single line</small>
            <standard>Standard - Single line</standard>
            <large>Large - Single line</large>
        </textfieldsize>
    </enum>
</property>
#155052
Sep 08, 2016 12:26
Vote:
 

Yes, that should also work. We were just using localization service n ot based on Xml language files.. therefore needed programmatic access

#155056
Sep 08, 2016 12:49
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.