Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nick Hoang 51 posts 180 karma points
    Mar 14, 2020 @ 10:08
    Nick Hoang
    0

    Issue with adding new property to an existing document type and put it on top of other properties (in the same tab)

    Hi,

    As the title, I'm having issue that, here's my code:

    protected bool AddPropertyType(IContentType contentType, IDataTypeDefinition dataType, string alias, string name, string description, string TabName, int sortOrder = 0, bool mandatory = false)
    {
        if (!contentType.PropertyTypeExists(alias))
        {                
            contentType.AddPropertyType(
                new PropertyType(dataType, alias)
                {
                    Name = name,
                    Description = description,
                    Mandatory = mandatory,
                    PropertyEditorAlias = dataType.PropertyEditorAlias,
                    SortOrder = sortOrder
                },
                TabName);                
            return true;
        }
        return false;
    }
    
    protected void ReOrderPropertyTypes(IContentType contentType, string groupName, string currentPropertyTypeAlias, int currentSortOrder) 
        {
            var group = contentType.PropertyGroups[groupName];
            if(group != null)
            {
                var otherPropertyTypes = group.PropertyTypes.Where(e => e.SortOrder >= currentSortOrder && e.Alias != currentPropertyTypeAlias)
                    .OrderBy(e=>e.SortOrder);
                foreach(var item in otherPropertyTypes)
                {
                    item.SortOrder = item.SortOrder + 1;                    
                }                
            }
        }
    
    AddPropertyType(abstractOpenGraphContentType, label, "nOTE", "NOTE", "", "OpenGraph", 0))
    ReOrderPropertyTypes(abstractOpenGraphContentType, "OpenGraph", "nOTE", 0);
    
    ApplicationContext.Current.Services.ContentTypeService.Save(globalConfigContentType);
    

    The code works well but the backoffice UI didn't work as expected, the new field (named "NOTE") displays in a random position, not on the top of "OpenGraph" tab.

    Does anyone have any recommendations to make it work?

    Best regards, Nick

Please Sign in or register to post replies

Write your reply to:

Draft