Copied to clipboard

Flag this post as spam?

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


  • Robert Ghafoor 33 posts 95 karma points
    Feb 11, 2013 @ 11:23
    Robert Ghafoor
    0

    V6 Using the new IContentType and add Property to PropertyGroup

    Hi

    I try to add properties to a PropertyGroup, the tab is created but the properties that i added to them is not showing in the correct tab thay all go to Generic Properties tab and if i look into the database at cmsPropertyType then propertyTypeGroupId is NULL for every properties that i added ? 

    foreach (PropertyGroup propertyGroup in contentType.PropertyGroups.Where(x => x.Name == propertyTab.Name))
                {
                    bool found = false;
    
                    foreach (var type in propertyGroup.PropertyTypes)
                    {
                        if(type.Alias == propertyType.Alias)
                        {
                            found = true;
                        }
                    }
    
                    if(!found)
                    {
                        propertyGroup.PropertyTypes.Add(propertyType);
                    }
                }

    Im using the following namespaces:

    using Umbraco.Core;
    using Umbraco.Core.Models;
    using Umbraco.Core.Services;
    using Umbraco.Core.Models.PropertyType;

     

  • Mathijs 27 posts 60 karma points
    Oct 30, 2013 @ 21:26
    Mathijs
    0

    Hi Robert,

    First check if your desired group exists. After that use as follow:

    if(desiredGroup == null) { 

    contentTypeItem.AddPropertyGroup(desiredGroup.Name);

    }

     contentTypeItem.MovePropertyType(propertyType.Alias, desiredGroup.Name);

     

     

Please Sign in or register to post replies

Write your reply to:

Draft